我不好意思问,但我真的很难从某些JSON中获取值。我似乎无法正确地访问数组的值。
我可以从这个Json获得值( 工作小提琴),它使用以下格式的json响应:
{
"items": [
{
"tags": [
"jqgrid"
],
"owner": {
"reputation": 21,
"user_id": 3038042,
"user_type": "registered",
"accept_rate": 70,
"profile_image": "https://www.gravatar.com/avatar/819ef95bfca002204f5bd00654fb9957?s=128&d=identicon&r=PG&f=1",
"display_name": "Amete",
"link": "http://stackoverflow.com/users/3038042/amete"
},
"is_answered": false,
"view_count": 5,
"answer_count": 1,
"score": 1,
"last_activity_date": 1423648956,
"creation_date": 1423605704,
"last_edit_date": 1423648956,
"question_id": 28442722,
"link": "http://stackoverflow.com/questions/28442722/jqgrid-set-focus-on-selectrow-not-working",
"title": "JqGrid Set Focus on SelectRow not working"
}
]
}但是我不能对下面的Json做同样的事情(失败的小提琴)
[{
"Manufacturer": "Toyota",
"Sold": 1200,
"Month": "2012-11"
}, {
"Manufacturer": "Ford",
"Sold": 1100,
"Month": "2012-11"
}, {
"Manufacturer": "BMW",
"Sold": 900,
"Month": "2012-11"
}, {
"Manufacturer": "Benz",
"Sold": 600,
"Month": "2012-11"
}]我知道我没有正确地访问数组,但是我尝试过的一切都失败了。
此外,使用JQuery $.getJSON方法看起来更简单,但我也无法使其工作.
如有任何建议,将不胜感激。
发布于 2015-02-11 12:40:21
第二组数据是一个纯数组,顶层没有命名元素名为item。
使用
var item = result[i];不
var item = result.item[i];JSFiddle: http://jsfiddle.net/am77Lm8w/3/
我把你的Ajax回调变成了测试数据的生命。
发布于 2015-02-11 12:41:35
在第二个json中没有items。
您需要使用var item = result[i];
https://stackoverflow.com/questions/28454507
复制相似问题