36

我需要在 json 的单个键中存储许多值。例如

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

像这样的东西。任何指针?

4

3 回答 3

86

使用数组:

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

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

于 2013-06-13T17:18:48.007 回答
9
{
  "number" : ["1","2","3"],
  "alphabet" : ["a", "b", "c"]
}
于 2013-06-13T17:18:34.187 回答
-5
{
    "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"
        }
    }
};
于 2017-03-03T11:07:04.327 回答