如何获取json对象中的子对象

2025-05-14 10:25:11
推荐回答(4个)
回答(1):

$.ajax({
url: './accounts.json',
type: 'get',
dataType: 'json account.models',
data: params,
success: function(json){
alert(eval(json.accounts).length);
return json.accounts;
},
error: error})

建议你使用js调试工具,强烈推荐firebug,看看你传入的参数到底是什么,你应该传进去的是字符串,用eval方法就能得到json对象了

回答(2):

$.ajax({
url: './accounts.json',
type: 'get',
dataType: 'json account.models',
data: params,
success: function(json){
alert(eval(json.accounts).length);
return json.accounts;
},
error: error})

建议你使用js调试工具,强烈推荐firebug,看看你传入的参数到底是什么,你应该传进去的是字符串,用eval方法就能得到json对象了

回答(3):

使用 videos的时候判断一下就可以了 可以这样写 if(data.videos){里边标识 videos属性存在}

回答(4):

var str = {"code":0,"data":[{"uid":"689791","username":"vaghyuzhihao","orgid":"627","status":"1","subname":"yuzhihao","roleids":"1","orgcode":"600251","name":"yuzhihao","mapid":"0","passwd":"","siteid":"0","createorgcode":"600251","alarmview":"0"}]};
var json = eval(str);
console.log(json.data[0].uid);