javascript中json数组的取值问题
概念性的东西就不说了,我直接给个例子。vartest=[{"id":1,"name":'李'},{"id":2,"name":'张'},{'id':3,name:'刘'}...
概念性的东西就不说了,我直接给个例子。
var test=[{"id":1,"name":'李'},{"id":2,"name":'张'},{'id':3,name:'刘'},{"id":4,"name":'wang'}]
我现在得到一个id=2,这么得到它相对应json对象里面的name,也就是怎么得到'张' 展开
var test=[{"id":1,"name":'李'},{"id":2,"name":'张'},{'id':3,name:'刘'},{"id":4,"name":'wang'}]
我现在得到一个id=2,这么得到它相对应json对象里面的name,也就是怎么得到'张' 展开
展开全部
//构建一个json对象
var pinpai = {
"0":{"美的":49,"三星":35,"海信":25,"格力":16,"方太":14},
"1":{"美的":49,"三星":35,"海信":25,"格力":16,"方太":14}
};
jiage = pinpai[0]['美的'];
源:
//构建一个json对象
var jb={"美的":49,"三星":35,"海信":25,"格力":16,"方太":14};
for(var key in jb){
alert(key); //json对象的key
alert(jb[key]); //json对象的值
}
var pinpai = {
"0":{"美的":49,"三星":35,"海信":25,"格力":16,"方太":14},
"1":{"美的":49,"三星":35,"海信":25,"格力":16,"方太":14}
};
jiage = pinpai[0]['美的'];
源:
//构建一个json对象
var jb={"美的":49,"三星":35,"海信":25,"格力":16,"方太":14};
for(var key in jb){
alert(key); //json对象的key
alert(jb[key]); //json对象的值
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询