Store multiple values in single key in json

前端 未结 3 483
离开以前
离开以前 2020-12-24 05:50

I need to store many values in single key of json. e.g.

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

Somethin

相关标签:
3条回答
  • 2020-12-24 06:17

    Use arrays:

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

    You can the access the different values from their position in the array. Counting starts at left of array at 0. myJsonObject["number"][0] == 1 or myJsonObject["alphabet"][2] == 'c'

    0 讨论(0)
  • 2020-12-24 06:18
    {
        "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"
            }
        }
    };
    
    0 讨论(0)
  • 2020-12-24 06:31
    {
      "number" : ["1","2","3"],
      "alphabet" : ["a", "b", "c"]
    }
    
    0 讨论(0)
提交回复
热议问题