我想循环遍历以下json并获得一个键等于ID的键。
{
"519c5056af2863f1d0341788357ebb81": {
"downloadUrl": "2F519c5056af2863f1d0341788357ebb81%2F519c5056af2863f1d0341788357ebb81?alt=media&token=f50d9b0f-579a-4c81-b12b-35ee7e6810e2",
"file_dislikes": 0,
"file_likes": 0,
"file_status": "Public",
"filename": "Another testing video",
"upload_date": "2016-09-03T04:48:04.283Z",
"user_id": "14nWy7qG6vN7rNdquzZNhX1QvbH2",
"video_avatar": "./images/video.jpg"
},
"99eed0bcc07d23f828c44c1721433c69": {
"downloadUrl": "2F99eed0bcc07d23f828c44c1721433c69%2F99eed0bcc07d23f828c44c1721433c69?alt=media&token=d9251647-567e-49df-b0da-d9525e10ed0e",
"file_dislikes": 0,
"file_likes": 0,
"file_status": "Public",
"filename": "Zac Brown Band - Sweet Annie ",
"upload_date": "2016-09-03T04:22:06.285Z",
"user_id": "14nWy7qG6vN7rNdquzZNhX1QvbH2",
"video_avatar": "./images/video.jpg"
}
}
我想获取其键等于519c5056af2863f1d0341788357ebb81
的项目,以便我可以在我的html中显示它,例如video.filename,video.video_avatar。
答案 0 :(得分:0)
您可以使用jQuery.each来迭代JSON-object
jQuery.each(json, function(key, value) {
if (key == "519c5056af2863f1d0341788357ebb81") {
console.log(value);
}
} );
要访问普通JS对象的字段,您只需使用[]
console.log(object["519c5056af2863f1d0341788357ebb81"]);