Javascript 如何迭代这个JSON?
我有一个json格式:Javascript 如何迭代这个JSON?,javascript,jquery,json,Javascript,Jquery,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 organiz
{
"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;ifor(var i=0;i
这不是一个有效的JSON这是你在那里得到的一些蹩脚格式的JSON,这是来自你的服务器还是第三方的?Jsonlint是一个很好的工具,可以检查你的JSON是否有效@JonKoops我确信换行符是一个输入错误,请删除它,它是一个有效的object@Robert可能吧,但我倾向于不做假设。尤其是在堆栈溢出方面;)
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]);
}
}