1.JQuery遍历JSON对象
//创建json对象
var user={
"id":"1001",
"name":"jok",
"sex":"男",
"age":25,
};
var info="";
$(function(){
//遍历json对象
$.each(user,function(key,value){
info=info+value+" ";
});
$("#message").addClass("bule");
$("#message").text(info);
});
2.JQuery遍历json数组
var grop={
"shenzhen":[
{"id":"1001","tname":"花旗集团"},
{"id":"1002","tname":"阿里巴巴"}
],
};
$(function(){
var str=""
var obj=grop.shenzhen;
$.each(obj,function(index){
str +=obj[index].id+" ";
str +=obj[index].tname+" ";
});
$("#msg").html(str);
});