【发布时间】:2017-05-08 20:26:26
【问题描述】:
嗨,我有一个 json 字符串
"{"data":[{"Id":14,"ConfigName":"Online Hrs","ConfigValue":"00:01-23:59"},{"Id":15,"ConfigName":"Offline Days","ConfigValue":"Sunday"},{"Id":0,"ConfigName":"CurrentTime","ConfigValue":"11:3"}]}"
我想查看ConfigValue 中的ConfigName“CurrentTime”。
目前我正在通过以下代码访问它
var d = JSON.parse(data).data;
d[2].ConfigValue
但有时 json 字符串会是
"{"data":[{"Id":14,"ConfigName":"Online Hrs","ConfigValue":"00:01-23:59"},{"Id":0,"ConfigName":"CurrentTime","ConfigValue":"11:3"}]}"
如果我想访问“CurrentTime”,现在根据上面的字符串
我将不得不写下面的代码
var d = JSON.parse(data).data;
d[1].ConfigValue
那么任何人都可以告诉如何访问它吗?因为数组可能随时更改,所以我不能像那样对数组索引进行硬编码。
【问题讨论】:
标签: javascript