Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

2 of 2
added 216 characters in body; edited title
Bojangles
  • 101.8k
  • 50
  • 175
  • 209

Parsing JSON array within array

I have the following code that gets the first 'name' in an array called 'feeds' within my JSON, I would like to now loop through the JSON and get each name. I haven't been able to get that loop to work.

JSON:

{
 "title": "Testing",
 "created_at": "2011年10月05日T16:23:26.217Z",
 "feeds": [{
 "0": {
 "name": "twitter",
 "key": "person1"
 },
 "1": {
 "name": "twitter",
 "key": "person2"
 },
 "_id": "4e8c847e02edc10035000003"
 }]
}

This gets the first title successfully:

$.getJSON(getthisshit, function (myJson) {
 var myfeed = myJson.feeds[0][0].name;
 alert(myfeed);
});

I tried to loop through doing something like this, but have not been able to get it to work:

$.getJSON(getthisshit, function (myJson) {
 $.each(myJson.feeds, function (i, item) {
 alert(item.name);
 });​
});
tuddy
  • 1.8k
  • 4
  • 31
  • 36
lang-js

AltStyle によって変換されたページ (->オリジナル) /