将JSON从一种格式转换为其他格式?

时间:2016-11-28 12:14:59

标签: java json

我有以下JSON

                "ID": "234AS",
                "Name": "SynchronousMate",
                "Type": "Node",
                "SubType": "SubNode",
                "Dynamic": "Yes",
                "DisplayName": "Sync",
                "Direct": "Yes",
                "Category": "IT",
                "Properties": {
                    "Property": [
                        {
                            "Name": "A",
                            "Value": "Anant"
                        },
                        {
                            "Name": "B",
                            "Value": "Bharat"
                        },
                        {
                            "Name": "C",
                            "Value": "Cynus"
                        },
                        {
                            "Name": "D",
                            "Value": "Dynana"
                        },
                        {
                            "Name": "E",
                            "Value": "Elegant"
                        },
                        {
                            "Name": "Bank",
                            "Value": "BOB"
                        },
                        {
                            "Name": "ipAddress",
                            "Value": "101.90.34.12"
                        },
                        {
                            "Name": "siteName",
                            "Value": "BRS-WDM-PSS-X7A6"
                        },
                        {
                            "Name": "Longitude",
                            "Value": 0
                        },
                        {
                            "Name": "FullName",
                            "Value": "network:10.254.0.46"
                        },
                        {
                            "Name": "NumberOfShelves",
                            "Value": 0
                        },
                        {
                            "Name": "GEOCODE.Latitude",
                            "Value": 0
                        }
                    ]
                },
                "Properties": ""
            }
..............................
..............................

如何将此JSON转换为此类

{

            "ID": "234AS",
            "Name": "SynchronousMate",
            "Type": "Node",
            "SubType": "SubNode",
            "Dynamic": "Yes",
            "DisplayName": "Sync",
            "Direct": "Yes",
            "Category": "IT",
            "A" : "Anant",
            "B" : "Bharat",
            "C" : "Cynus",
            "D" : "Dynana",
            "E" : "Elegant",
            "Bank" : "BOB",
            "ipAddress" :  "101.90.34.12",
            "siteName" : "BRS-WDM-PSS-X7A6",
            "Longitude" : ""0",
            "FullName" : "network:10.254.0.46",
            "NumberOfShelves" : 0,
            "GEOCODE.Latitude" : 0




        },
............................
............................

2 个答案:

答案 0 :(得分:0)

您可以循环properties并创建一个Map,其键值为Name,值为Value的值。

答案 1 :(得分:-1)

简单来说,获取/存储属性JsonArray。然后迭代它放入 Map中的数组元素。然后将地图添加到JSON的另一半。