I've got a problem where I can't seem to query my JSON coming back, I can print out the entire response though, here's my JSON response, I can only see this when I do a msgBox()
prompt:
{ "Addresses" :
"[{
Building=Megatron Skyscraper,
BuldingId=1998,
AccountId=2000,
Number=007,
Name=Megatron
},{
Building=StarScream Skyscraper,
BuldingId=1999,
AccountId=2001,
Number=008,
Name=StarScream
}]"}
And here's my code:
function getReadyStateHandler(req)
{
// Return an anonymous function that listens to the
// XMLHttpRequest instance
return function ()
{
// If the request's status is "complete"
if (req.readyState == 4)
{
// Check that a successful server response was received
if (req.status == 200)
{
msgBox("JSON Response recieved...");
var addresses = req.responseText.toJSON();
msgBox(req.responseText.toJSON());
}
else
{
// An HTTP problem has occurred
alert("HTTP error: " + req.status);
}
}
}
}
I've tried everything from addresses.Address[0].City
and addressess.Addresses[0].City
and many others - but this is slightly confusing!
City
key in your object. AndAdresses
is a string for some reason. Even if you useJSON.parse()
oreval
it will not work as the sting is not valid for parsing. You have to make sure that you get a proper response first. – Trap