javascript - Accessing JSON key values without loop -
receiving json response this
responses = { "http://www.example.com/firts": { error: [object object], response: [object object], body: [object object] }, "http://www.example.com/second": { error: [object object], response: [object object], body: [object object] }, "http://www.example.com/third": { error: [object object], response: [object object], body: [object object] } }
var urls = ["http://www.example.com/firts", "http://www.example.com/second", "http://www.example.com/third"];
it works fine in loop this:
for(url in responses) { var response = responses[url]; console.log('got response '+response.response.statuscode); }
but not able access outside loop. tried:
var response = responses[urls[0]]; console.log('got response '+response.response.statuscode);
and
var response = responses["http://www.example.com/firts"]; console.log('got response '+response.response.statuscode);
and
var response = responses[0][urls[0]]; console.log('got response '+response.response.statuscode);
but nothing worked me.
your json isn't json. set of javascript object literals, , when hits [object object]
, errors because can't have someidentifier someotheridentifier
in array literal.
values in arrays have separated commas, looks intended have object literals there specific values. when create javascript, need express proper object literals instead of casting objects strings.
Comments
Post a Comment