jquery getJson method for complex json how to get values using jquery each method -



jquery getJson method for complex json how to get values using jquery each method -

hi newbie json dont know how iterate json on $.each function worked on display shows value undefined not sure why

here how json looks saved new file data.json

{ "users":[ { "firstname":"ray", "lastname":"villalobos", "joined": { "month":"january", "day":12, "year":2012 } }, { "firstname":"john", "lastname":"jones", "joined": { "month":"april", "day":28, "year":2010 } } ]}

here need iterate name joined date in json , iterate on jquery this

$(function(){ $(document).on('click', '.users', function(e){ e.preventdefault(); $.getjson( "js/data.json", function( info ) { var items = []; $.each( data.users, function( key, val ) { console.log(data.users); items.push( "<li id='" + data.users.firstname + "'><span><p>" + data.users.firstname + "</p></span></li>" ); }); $( "<ul/>", { "class": "users-lists", html: items.join( "" ) }).appendto( ".nlst" ); }); }); });

help me out

in jquery code alter line

items.push( "<li id='" + data.users.firstname + "'><span><p>" + data.users.firstname + "</p></span></li>" );

to

items.push( "<li id='" + val.firstname + "'><span><p>" + val.firstname + "</p></span></li>" );

jquery doc here

jquery json each

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -