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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17093180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 19:51:31  来源:igfitidea点击:

Store multiple values in single key in json

arraysjson

提问by Gaurav

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

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

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

Something like this. Any pointers?

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

回答by Elliot Bonneville

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] == 1or myJsonObject["alphabet"][2] == 'c'

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

回答by marekful

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

回答by vicky

{
    "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"
        }
    }
};