日期:2014-05-16  浏览次数:20376 次

求助jquery js 怎么遍历下面这个json??
求助jquery js 怎么遍历下面这个json??
HTML code

{"num":0,"name":"\u9006\u6218","actor":"\u8c22\u9706\u950b,\u5468\u6770\u4f26,\u767d\u51b0,\u6797\u9e4f,\u5b89\u5fd7\u6770,\u5ed6\u542f\u667a","year":"2011","director":"\u6797\u8d85\u8d24"}



------解决方案--------------------
JScript code

var json='{"num":0,"name":"\u9006\u6218","actor":"\u8c22\u9706\u950b,\u5468\u6770\u4f26,\u767d\u51b0,\u6797\u9e4f,\u5b89\u5fd7\u6770,\u5ed6\u542f\u667a","year":"2011","director":"\u6797\u8d85\u8d24"} ';
var obj=decodeURIComponent(json);
o=eval('('+obj+')');
alert(o.name);

------解决方案--------------------
楼主是不知道js数组的遍历方式吗??
2楼稍作修改:
for (var key in o){
 alert(o[key]);
}
------解决方案--------------------
var json = {"1": "第一个"};
$.each(json, function(key, value){
key //为"1"
value //为"第一个"
})
依次类推