Reputation: 1733
I have a json of the form :
{
"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"
} ]
}
How can I get each name value pair in this using jQuery / JS?
I need to get the name value pairs inside the [ ]
I've seen solutions suggestin $.each()
function but that seems to work only for JSON of the form {name:value}
.
Sorry I'm new to this....
Upvotes: 0
Views: 99
Reputation: 13549
You may use:
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]);
}
}:
Upvotes: 1
Reputation: 77
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]);
}
}
Upvotes: 0