So I’m using Yahoo’s API to translate coordinates to a zip code. The JSON it returns is this:
{
"ResultSet": {
"version": "1.0",
"Error": 0,
"ErrorMessage": "No error",
"Locale": "us_US",
"Quality": 99,
"Found": 1,
"Results": [{
....
}]
What I am doing is:
$.getJSON("http://where.yahooapis.com/geocode?q=" + lat + ",+" + lon + "&gflags=R&flags=J", function(data){
console.log(data.ResultSet.Results.postal);
});
What I listed above obviously doesn’t work. My question is: how do I access the data within the Results array?
Thanks
as Results is an array does changing the console log line to the following work?
In which case just loop through the array to get each each element. The code to get JSON looks fine to me, I assume you just missed the array element bit 🙂