jquery - Trouble with $.getJSON - looks like arrays inside of arrays -


ok, i'm new jquery json stuff. i'm trying access actions > name node in below json output. looks "actions" array inside of "data" array. way getting json results can access "message" portion correctly using fb.message , can access "name" node under "from" fb.from.name. how access "name" node under "actions" array?

thanks help!!

code:

({ "data": [{          "id": "1755670903_1287007912714",          "from": {             "name": "lifebridge church",             "id": "1755670903"          },          "message": "due weather, church service tomorrow canceled. see next week!",          "icon": "http://photos-d.ak.fbcdn.net/photos-ak-snc1/v27562/23/2231777543/app_2_2231777543_9553.gif",          "actions": [             {                "name": "\u0040lifebridgetx on twitter",                "link": "http://twitter.com/lifebridgetx?utm_source=fb&utm_medium=fb&utm_campaign=lifebridgetx&utm_content=33711605665505280"             }          ],          "type": "status",          "application": {             "name": "twitter",             "id": "2231777543"          },          "created_time": "2011-02-05t02:20:48+0000",          "updated_time": "2011-02-05t02:20:48+0000"       },       {          "id": "1755670903_1281724020620",          "from": {             "name": "lifebridge church",             "id": "1755670903"          },          "message": "service tonight @ 5:30... meet @ eddins elementary school in mckinney.  http://see.sc/8l4cwo || praying god glorified!",          "icon": "http://photos-d.ak.fbcdn.net/photos-ak-snc1/v27562/23/2231777543/app_2_2231777543_9553.gif",          "actions": [             {                "name": "\u0040lifebridgetx on twitter",                "link": "http://twitter.com/lifebridgetx?utm_source=fb&utm_medium=fb&utm_campaign=lifebridgetx&utm_content=31388610301272065"             }          ],          "type": "status",          "application": {             "name": "twitter",             "id": "2231777543"          },          "created_time": "2011-01-29t16:30:03+0000",          "updated_time": "2011-01-29t16:30:03+0000"       }] }); 

follow-up code additional questions:

$.each(json.data,function(i,fb){     if (!fb.message) continue;     facebookpost += '<li class="ui-li ui-li-static ui-btn-up-c" role="option" data-theme="c">' + fb.message + ' <br /><span class="via">' + fb.created_at + ' via ' + fb.actions[0].name + '</span></li>';     $('#facebookposts li:first').after(facebookpost); }); 

i'm assuming when fb, fb = data[0]. then:

fb.actions; // gives actions array fb.actions[0]; // gives first object in actions array fb.actions[0].name; // gives name value of first object in actions array 

from question in comments, skip on items when value doesn't exist:

$.each(json.data,function(i,fb){     if (!fb.message) return true; // true keep going, false quit     facebookpost += '<li class="ui-li ui-li-static ui-btn-up-c" role="option" data-theme="c">' + fb.message + ' <br /><span class="via">' + fb.created_at + ' via ' + fb.actions[0].name + '</span></li>';     $('#facebookposts li:first').after(facebookpost); }); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -