在遍历json时获得不一致的输出 [英] Getting inconsistent output on iterating over json
问题描述
set_options_list = function(selctelm, json){
$(selctelm).empty();
for ( key in json.array.F_02_0010){
val = json.array.F_02_0010[key]
console.log(key, typeof val, val[0], val[1]);
};
}
这是我的json数组:
Here is my json array:
json.array = {F_02_0010 : [{0 : "-------"},
{1:"20億円以上"},
{2:"14億円以上20億円未満"},
{3:"7億円以上14億円未満"},
{4:"7000万円以上7億円未満"},
{5:"7000万円未満"}],
F_02_0110 : [{0 : "-------"},
{1:"10億円以上"},
{2:"7億円以上10億円未満"},
{3:"4億円以上7億円未満"},
{4:"4000万円以上4億円未満"},
{5:"4000万円未満"}],
F_02_0210 :[{0 : "-------"},
{1:"10億円以上"},
{2:"7億円以上10億円未満"},
{3:"4億円以上7億円未満"},
{4:"5000万円以上4億円未満"},
{5:"5000万円未満"}],
"default": [{0 : "-------"}]
};
我正在获取undefined
来访问键和值.这可能是什么原因?
这是console.log结果:
I'm getting undefined
to access key and value.What could be the reason?
Here is console.log result:
0 object ------- undefined
1 object undefined 20億円以上
2 object undefined undefined
3 object undefined undefined
4 object undefined undefined
5 object undefined undefined
我不确定为什么在这里变得不确定吗?
I'm not sure why I'm getting undefined here?
推荐答案
有意义:
json.array.F_02_0010 [0]是{0:"-------"},
json.array.F_02_0010[0] is {0 : "-------"},
json.array.F_02_0010 [1]是{1:"200亿円以上"}}
json.array.F_02_0010[1] is {1:"20億円以上"},
json.array.F_02_0010 [2]是{2:"14亿円以上20亿円未満"},
json.array.F_02_0010[2] is {2:"14億円以上20億円未満"},
等...
所以:
json.array.F_02_0010 [0] [i]如果"i == 0"为"-------",否则为未定义
json.array.F_02_0010[0][i] is "-------" if i == 0, undefined otherwise
json.array.F_02_0010 [1] [i]如果"i == 1"为"200亿円以上",否则未定义
json.array.F_02_0010[1][i] is "20億円以上" if i == 1, undefined otherwise
json.array.F_02_0010 [2] [i]如果i == 2,则为"14亿円以上20亿円未満",否则未定义
json.array.F_02_0010[2][i] is "14億円以上20億円未満" if i == 2, undefined otherwise
等...
这篇关于在遍历json时获得不一致的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!