日期:2014-05-20  浏览次数:20724 次

JAVA 如何根据一个json更新另一个json文件 (两个json结构不一样 B是A的子集)
例如
{
    "A": [
                {
                "code" : "AAA",
                "type" : "a",
                "name" : "1"
                },
                {
                "code" : "BBB",
                "type" : "b"
                "name" : "2"
                },
                {
                "code" : "CCC",
                "type" : "c",
                "name" : "3"
                }
     ]

}

{
    "B": [
                {
                "code" : "AAA",
                "type" : "e"
                },
                {
                "code" : "CCC",
                "type" : "f"
                }
     ]

}

预想结果

{
    "A": [
                {
                "code" : "AAA",
                "type" : "e",
                "name" : "1"
                },
                {
                "code" : "BBB",
                "type" : "b"
                "name" : "2"
                },
                {
                "code" : "CCC",
                "type" : "f",
                "name" : "3"
                }
     ]

}
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>
xxx
</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
var x = {
"A": [{
"code": "AAA",
"type": "a",
"name": "1"
},
{
"code": "BBB",
"type": "b",
"name": "2"
},
{
"code": "CCC",
"type": "c",
"name": "3"
}]

};
var y = {
"B": [{
"code": "AAA",
"type": "e"
},
{
"code": "CCC",
"type": "f"