关闭

得到json 中的key 值

标签: jsonJqueryjavascriptkey
198人阅读 评论(0) 收藏 举报

测试数据:

var tree_data2 = {}
tree_data2['foodmart'] = {name: 'Foodmart', type: 'folder'}
tree_data2['foodmart']['children']={}
tree_data2['foodmart']['children']['appetizer']={name: 'Appetizer', type: 'item'}
tree_data2['foodmart']['children']['main-course']={name: 'Main Course', type: 'item'}
tree_data2['foodmart']['children']['Drinks']={name: 'Drinks', type: 'folder'}


jquery 方式: 

$.each(tree_data2['foodmart']['children'], function(key,value) {

console.log(key+": "+value['name'])

})


js 方式:

var jsonv = tree_data2["foodmart"]['children'];
for(var key in jsonv){
       console.log(jsonv[key]["name"])
}


1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:3028次
    • 积分:135
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类