在json中将单个键存储多个值

时间:2013-06-13 17:17:26

标签: arrays json

我需要在json的单个键中存储许多值。 e.g。

{
  "number" : "1","2","3",
  "alphabet" : "a", "b", "c"
}

像这样的东西。有什么指针吗?

3 个答案:

答案 0 :(得分:64)

使用数组:

{
    "number": ["1", "2", "3"],
    "alphabet": ["a", "b", "c"]
}

您可以从阵列中的位置访问不同的值。计数从数组左侧开始,为0. myJsonObject["number"][0] == 1myJsonObject["alphabet"][2] == 'c'

答案 1 :(得分:6)

{
  "number" : ["1","2","3"],
  "alphabet" : ["a", "b", "c"]
}

答案 2 :(得分:-7)

{
    "success": true,
    "data": {
        "BLR": {
            "origin": "JAI",
            "destination": "BLR",
            "price": 127,
            "transfers": 0,
            "airline": "LB",
            "flight_number": 655,
            "departure_at": "2017-06-03T18:20:00Z",
            "return_at": "2017-06-07T08:30:00Z",
            "expires_at": "2017-03-05T08:40:31Z"
        }
    }
};