ajax - getJSON() to access data at multiple levels -
i'm trying use .getjson
extract data validating .json:
{ "data": [ { "claim": { "id": "3567", "user_id": "341", "expiration": "2013-07-06 23:59:59", "content": "apples", "point": "85.71", "exp": "jul 6, 2013" }, "user": { "score": "-1030.17", "id": "341" }, "claimresponse": { "point": "80", "response_type": "yeah", "claim_id": "3567" }, "viewer": { "isowner": "0", "isresponsed": "1", "response": "yeah", "lockedinpoint": "80" } }, { "claim": { "id": "3576", "user_id": "342", "expiration": "2013-06-15 00:00:00", "content": "oranges", "point": "86.42", "exp": "jun 15, 2013" }, "user": { "score": "-3128.13", "id": "342" }, "claimresponse": { "point": "71", "response_type": "yeah", "claim_id": "3576" }, "viewer": { "isowner": "0", "isresponsed": "1", "response": "yeah", "lockedinpoint": "71" } }, { "claim": { "id": "3577", "user_id": "342", "expiration": "2013-07-01 00:00:00", "content": "peanuts", "point": "80.25", "exp": "jul 1, 2013" }, "user": { "score": "-3128.13", "id": "342" }, "claimresponse": { "point": "67", "response_type": "yeah", "claim_id": "3577" }, "viewer": { "isowner": "0", "isresponsed": "1", "response": "yeah", "lockedinpoint": "67" } } ], "errors": [], "success": true, "code": 200 }
(a snippet of many records) i've never tried extract data multiple levels down this, , can't @ it.
my code's pretty straightforward:
$.getjson("/api/getuserclaims.json",function(data){ $.each(data.claim, function(i,claim){ content = '<p>' + claim.id + '</p>'; $(content).appendto("#my-claims"); alert(content); }); });
according console, json loading properly. i've tried getting @ few ways, using data.claim[0].id
grab array instead of object. i'm overlooking simple. ideas?
there no data.claim
.
you have array in there first, data[0].claim
, data[1].claim
etc.
$.each(data, function(i,x){ var claim = x.claim; content = '<p>' + claim.id + '</p>'; $(content).appendto("#my-claims"); alert(content); });
Comments
Post a Comment