I have a callback function which is executed when I return from making a YQL statement:
function cbfunc(json)
{
if (json.query.count)
{
var data = json.query.results.json;
$("#output").append(data.raw[0]["176932931"].name);
}
This is the JSON object that I'm working with:
http://www.easports.com/iframe/fifa14proclubs/api/platforms/PS4/clubs/51694/members
I'm getting the result of the json and assigning it to the data variable. However, when I try to access the data variable (data.raw[0]["176932931"].name), it's giving me the following error: data.raw[0] is undefined.
This is what is returned when I console.log(json):
http://i.imgur.com/mvYMYYI.png
This is what is returned when I console.log(data);
http://i.imgur.com/fxBqvSJ.png
HOWEVER, when I assign the JSON string straight to the data variable, it works correctly, and I'm able to access properties of the object with no errors:
var data = {"raw":[{"176932931":{"name":"Shipdawg","blazeId":176932931,"clubStatus":0,"onlineStatus":0,"nucleusId":2266699357,"personaName":"Shipdawg"},"182141183":{"name":"Beks8","blazeId":182141183,"clubStatus":0,"onlineStatus":0,"nucleusId":2272736228,"personaName":"Beks8"},"219929617":{"name":"ChelseaFC_26","blazeId":219929617,"clubStatus":0,"onlineStatus":0,"nucleusId":2304510098,"personaName":"ChelseaFC_26"},"457588267":{"name":"Lazy__Rich","blazeId":457588267,"clubStatus":0,"onlineStatus":0,"nucleusId":2495578386,"personaName":"Lazy__Rich"},"517570695":{"name":"x0__andrew__0x","blazeId":517570695,"clubStatus":0,"onlineStatus":1,"nucleusId":2549150176,"personaName":"x0__andrew__0x"},"912396727":{"name":"mizz00-","blazeId":912396727,"clubStatus":0,"onlineStatus":1,"nucleusId":1000118566560,"personaName":"mizz00-"},"915144354":{"name":"MisterKanii","blazeId":915144354,"clubStatus":2,"onlineStatus":0,"nucleusId":2281969661,"personaName":"MisterKanii"}}]};
With this change, I get a slightly different object back when I console.log(data):
http://i.imgur.com/VNCcwmx.png
But I can't use that as a solution since the data variable will be different depending on my YQL statement.
So the question is, how am I meant to access the properties of the first object? This one:
http://i.imgur.com/fxBqvSJ.png
I've looked all over SO and Google and I just can't seem to find a solution.
Thanks.