我们具有以下JSON结构
我正在尝试访问数据数组值。我注意到值名称是数字,并且在尝试定义逻辑时以某种方式无法识别它们。以下所有内容都有错误。
series[0].data[0].0
series[0].data[0].0[0]
series[0].data[0]."0"
series[0].data[0].'0'
错误消息是“未找到成员'0'”
(交换逻辑的最后一部分,每次尝试都出现相同的错误)
请帮助我找出是否有sytanx问题或其他问题?
这是第一部分,只有未处理的伪数据
{
"request": {
"command": "dummy",
"series_id": "dummy"
},
"series": [
{
"series_id": "dummy",
"name": "dummy",
"units": "dummy",
"f": "W",
"unitsshort": "dummy",
"description": "dummy",
"copyright": "dummy",
"source": "dummy",
"start": "19900406",
"end": "20180803",
"updated": "2018-08-08T14:01:44-0400",
"data": [
[
"20180803",
2.104
],
[
"20180727",
2.11
],
[
"20180720",
2.042
],
...
顺便说一句,我正在使用IBM Workload Scheduler访问API来检索此数据。工具framewrok让我指定要从结果中获取的JSON属性。如果我尝试获取整个第一个数组值,我会成功
series[0].data[0]
JSONResult:[20180803,2.104]
更新
从IBM Workload Scheduler添加屏幕
答案 0 :(得分:0)
如评论中所述,如果要获取值20180803
,则应使用series[0].data[0][0]
。这是一个示例:
let theData = {
"request": {
"command": "dummy",
"series_id": "dummy"
},
"series": [{
"series_id": "dummy",
"name": "dummy",
"units": "dummy",
"f": "W",
"unitsshort": "dummy",
"description": "dummy",
"copyright": "dummy",
"source": "dummy",
"start": "19900406",
"end": "20180803",
"updated": "2018-08-08T14:01:44-0400",
"data": [
[
"20180803",
2.104
],
[
"20180727",
2.11
],
[
"20180720",
2.042
]
]
}]
}
console.log(theData.series[0].data[0][0])