【发布时间】:2017-09-11 13:24:03
【问题描述】:
我有以下代码:
j = 1;
while (j < 50) {
//requirement:
console.log(JSONitem [j]["criteria"]);
reqtest = Object.keys(JSONitem [j]["criteria"]);
....
j++;
}
但是当我执行这个时,我得到以下错误:
TypeError: JSONitem[j] 未定义
console.log部分的输出对象是对的,而且在这一行中也是上面的TypeErro。我认为,“j”不会替换数字,但在输出控制台中它可以工作......
谢谢!
【问题讨论】:
-
你的 json 是什么样子的?
-
你的第一行会返回一个错误
while (j = 1; j < 50) {应该是var j = 1; while (j < 50) { -
这不是JSON(也不是JSON项目)而是一个常规对象:What is the difference between JSON and Object Literal Notation?
标签: javascript jquery json while-loop key