在我正在使用的一些JSON中,它具有以下内容:
"value": [["field1", "field2"]]
我需要能够提取field1
和field2
。我该怎么做?
答案 0 :(得分:4)
它只是一个数组中的数组,因此您可以使用索引访问数据:
data.value[0][0] == 'field1'
data.value[0][1] == 'field2'
答案 1 :(得分:1)
您可以访问它:
var test = { "value": [ [ "field1", "field2" ] ] };
^ ^ ^ ^ ^
| | | | |
[1] [2|3] [4] [5]
// [1] test is an object
// [2] test.value is an array of array
// [3] test.value[0] is an array("field1", "field2")
// [4] test.value[0][0] is "field1"
// [5] test.value[0][1] is "field2"
答案 2 :(得分:0)
这应该有效:
field1 = value[0][0]
field2 = value[0][1]
答案 3 :(得分:0)
假设您已经解析过它:
var o = {"value": [["field1", "field2"]]};
console.log(o.value[0][0], o.value[0][1]);