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

谁知道jquery如何遍历解析json
json文件:
{"succeed":"true",
  "n1":{"ID":"1","Sort":"0","Name":"gfngfngf","Explain":"gfngfng"},
  "n2":{"ID":"2","Sort":"0","Name":"gfngfngf","Explain":"gfngf"},
  "n3":{"ID":"3","Sort":"0","Name":"gngf","Explain":"gfngf"}
}
请问:像这样的json文件如何用jquery遍历显示,主要是将n1,n2,n3,……遍历出来?



------解决方案--------------------
function test(){
var jsons = {"succeed":"true",
"n1":{"ID":"1","Sort":"0","Name":"gfngfngf","Explain":"gfngfng"},
"n2":{"ID":"2","Sort":"0","Name":"gfngfngf","Explain":"gfngf"},
"n3":{"ID":"3","Sort":"0","Name":"gngf","Explain":"gfngf"}
};
$.each(jsons,function(i,n){
if(i == "succeed"){
alert(i + "--" + n);
}
else{
alert(i + "--" + n.ID + "--" + n.Name);
}
});
}