java后台,将取到json数据,组装另一组特定json中

大佬们,请问如何取json对象中的值,组装另一组json对象中

如果为取eventAtt.Protection的值,则SnapPolygon.color.r=0,id的值为Sectionnumber,point的值为area,tips的值为#area#。
如果为eventAtt.Removalarea,则SnapPolygon.color.r=255,d的值为Sectionnumber,point的值为area,tips的值为#area#

取值的对象代码

var eventAtt={
        "Protection": [
            {
                "area": [
                    [
                        0.2,
                        0.2
                    ],
                    [
                        0.5,
                        0.2
                    ],
                    [
                        0.5,
                        0.5
                    ],
                    [
                        0.2,
                        0.5
                    ]
                ],
                "Sectionnumber": 1
            },
            {
                "area": [
                    [
                        0.2,
                        0.2
                    ],
                    [
                        0.5,
                        0.2
                    ],
                    [
                        0.5,
                        0.5
                    ],
                    [
                        0.2,
                        0.5
                    ]
                ],
                "Sectionnumber": 3
            }
        ],
        "Removalarea": [
            {
                "area": [
                    [
                        0.2,
                        0.2
                    ],
                    [
                        0.5,
                        0.2
                    ],
                    [
                        0.5,
                        0.5
                    ],
                    [
                        0.2,
                        0.5
                    ]
                ],
                "Sectionnumber": 2
            },
            {
                "area": [
                    [
                        0.2,
                        0.2
                    ],
                    [
                        0.5,
                        0.2
                    ],
                    [
                        0.5,
                        0.5
                    ],
                    [
                        0.2,
                        0.5
                    ]
                ],
                "Sectionnumber": 4
            }
        ]
    };

示例的代码

var json ={"SnapPolygonList":{"SnapPolygon":[{"id":"1","polygonType":"1","color":{"r":"0","g":"255","b":"0"},"tips":"#1#","isClosed":"true","pointList":{"point":[{"x":"0.324415","y":"0.496516"},{"x":"0.538462","y":"0.486063"},{"x":"0.438127","y":"0.806620"},{"x":"0.269231","y":"0.759582"}]}},{"id":"2","polygonType":"1","color":{"r":"255","g":"0","b":"0"},"tips":"#2#","isClosed":"true","pointList":{"point":[{"x":"0.168896","y":"0.728223"},{"x":"0.650502","y":"0.780488"},{"x":"0.493311","y":"0.945993"},{"x":"0.143813","y":"0.970383"},{"x":"0.157191","y":"0.949477"}]}}]}};

组装的值,需要放的位置

var jsonlist= {
            "SnapPolygonList":{
                "SnapPolygon":[
                    {
                        "id":Sectionnumber,
                        "polygonType":"1",
                        "color":{
                            "r":"0",
                            "g":"255",
                            "b":"0"
                        },
                        "tips":"#Sectionnumber#",
                        "isClosed":"true",
                        "pointList":{
                            "point":[
                                area
                            ]
                        }
                    },
                    {
                        "id":Sectionnumber,
                        "polygonType":"1",
                        "color":{
                            "r":"255",
                            "g":"0",
                            "b":"0"
                        },
                        "tips":"#区域编号#",
                        "isClosed":"true",
                        "pointList":{
                            "point":[
                                area
                            ]
                        }
                    }
                ]
            }
        };
阅读 1.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题