[英]How do I iterate through this JSON?
我有一個形式的json:
{
"SentenceFacts": [
{
"Objective : ": "none"
},
{
" Seeking a challenging position where my analytical and problem solving skills can be put in for the successful execution of the organizations projects .": "none"
},
{
"Summary : ": "none"
} ]
}
如何使用jQuery / JS獲得每個名稱值對?
我需要在[ ]
獲取名稱值對
我已經在$.each()
函數中看到了建議的解決方案,但這似乎僅適用於{name:value}
形式的JSON。
抱歉,我是新來的...。
您可以使用:
for(var i=0; i<json.SentenceFacts.length; i++) {
var item = json.SentenceFacts[i];
for(var prop in item) {
// prop here is "Objective", " Seeking a challenging position ..." etc
console.log("key: " , prop);
console.log("value: ", item[prop]);
}
}:
for (var i = 0; i < jsonObj.SentenceFacts.length; i++) {
for (var key in jsonObj.SentenceFacts[i]) {
jsonObj.SentenceFacts[i].hasOwnProperty(key) && console.log(key, jsonObj.SentenceFacts[i][key]);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.