在JSON单个键存储多个值 [英] Store multiple values in single key in json

查看:763
本文介绍了在JSON单个键存储多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要多值存储在JSON的单个键。例如。

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

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

这样的事情。任何指针?

Something like this. Any pointers?

推荐答案

使用数组:

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

您可以访问他们的阵列中的位置不同的值。在阵列的左边为0开始计数 myJsonObject [数量] [0] == 1 myJsonObject [字母] [2] =='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'

这篇关于在JSON单个键存储多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆