php - Parse Nested JSON With JQuery -


i'm new json , struggling this. i've read countless other posts , web pages can't seem figure out.

i'm using php output json (from data database) code:

    header('content-type: application/json');     echo json_encode($data); 

here json:

{     "x0": {         "id": "1",         "name": "rob",         "online": "1",         "gender": "m",         "age": "29",         "height": "5'8''",         "build": "average",         "ethnicity": "white",         "description": "art geek person",         "looking_for": "anything",         "image": "4fs5d43f5s4d3f544sdf.jpg",         "last_active": "29-06-11-1810",         "town": "manchester",         "country": "uk",         "distance": 0.050973560712308     },     "x1": {         "id": "2",         "name": "dave",         "online": "1",         "gender": "m",         "age": "29",         "height": "5'8''",         "build": "average",         "ethnicity": "white",         "description": "art geek person",         "looking_for": "anything",         "image": "4fs5d43f5s4d3f544sdf.jpg",         "last_active": "29-06-11-1810",         "town": "manchester",         "country": "uk",         "distance": 0.050973560712308     } } 

i think problem i'm having json nested(might wrong there)?.

this jquery:

function fetchprofiles() {     var url='http://url.com/here';     var = 0;     var handle = 'x'.i;      $.getjson(url,function(json){         $.each(json.results,function(i,profile){            $("#profiles").append('<p><img src="'+profile.handle.image+'" widt="48" height="48" />'+profile.handle.name+'</p>');            i++;         });     }); } 

any ideas or suggestions appreciated!

thanks!

i think problem call $.each on json.results (if json showed us).

you sholud do:

    $.each(json,function(i,profile){        $("#profiles").append('<p><img src="'+profile.image+'" widt="48" height="48" />'+profile.name+'</p>');     }); 

look @ fiddle here: http://jsfiddle.net/encvd/1/ (it alerst image property of json object)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -