如何将Key值添加到JSON数组

时间:2014-09-08 18:53:33

标签: json

我有这个JSON有效的JSONArray

[
    {
        "RestaurantName": "OhrisHome",
        "Locality": "Near Office"
    },
    {
        "RestaurantName": "SwagtahtHome",
        "Locality": "Near Home"
    }
]

我需要用一些名字来识别这个数组

所以我试图为这个JSON数组添加一个Key,如图所示

{
  "Type" : "Home"
    [
        {
            "RestaurantName": "OhrisHome",
            "Locality": "Near Office"
        },
        {
            "RestaurantName": "SwagtahtHome",
            "Locality": "Near Home"
        }
    ]
}

1 个答案:

答案 0 :(得分:1)

在对象中,它们的键将是数组的名称,值将是数组本身。只需更改" ArrayName"更适合的事情。

{
 "Type" : "Home",
 "ArrayName" : 
  [
    {
        "RestaurantName": "OhrisHome",
        "Locality": "Near Office"
    },
    {
        "RestaurantName": "SwagtahtHome",
        "Locality": "Near Home"
    }
  ]
}