Recently posted about looking through some json output from an API and got pointed to $getJSON and for loop issue
But im still really struggling and nothing I do works.
I have the following output from an API call :
{
"about": {
"name": "API",
"version": "2018.1.25.1",
"method": "get"
},
"sessions": {
"0": {
"sessionid": "c6fac08ad020cd10c377b77b81aac2ed19c08111",
"id": "121667",
"geolat": "51.9125118",
"geolon": "-2.1210269"
},
"1": {
"sessionid": "4f3da85c4905ee8c2a57ac48a22184b93fc2f680",
"id": "122589",
"chatstarted": "2018-02-24 23:41:51",
"geolat": "51.9125118",
"geolon": "-2.1210269"
}
},
"rescode": "200",
"executed": "nokeyfound-",
"queries": "5"
}
I just cant get it to loop through the "sessions"
part of the Json.
The below "sort of works" but doesnt work at all, no errors, no output when loading it using $.getJSON
(rather than just manually creating the object)
$.getJSON('https://api.php', function (Json) {
for (i in Json.sessions) {
alert(Json.sessions[i].id);
}
Surely it can't be that hard to just loop through only part of the data returned (the sessions) part.
What on earth am I doing wrong with this loop?
I just want to output sessionid on both rows. Seems impossible and been at this now for 9 hours straight no luck,
There has to be a way to just look at the sessions part and loop through the bits of that? surely? (0, 1 ,2 ,3 etc.. )
P.S I'm new to Javascript and JSON in particular and this is driving me insane.