1

I have this json from google api:

{
   "results" : [
      {

         "formatted_address" : "1 Broadway, New York, NY 10021, USA",
      }
   ],
   "status" : "OK"
}

how to get the value of "formatted_address"?

with this code (using jquery) I only get "results is Array"

$.getJSON(jsonFile, function(data){

    $.each(data, function(key, val){
        alert(key + ' is ' + val);
    });

});

In php it is very easy but I need this to be client-side

4
  • 2
    data.results[0].formatted_address Commented Sep 16, 2013 at 17:44
  • When you solved your problem please delete your question (in case there are no answers yet) or answer your own question - but do not put "solved" in the title. Commented Sep 16, 2013 at 17:59
  • I think the keyword recursive in the title is misleading. Commented Sep 16, 2013 at 18:02
  • @ThiefMaster I have low reputation so I had to wait 7hrs before self-answering Commented Sep 17, 2013 at 8:58

1 Answer 1

1
$.getJSON(jsonFile, function(data) {
    $.each(data.results, function(key, val) {
        alert(key + ' is ' + val);
    });
});

This should work.

Sign up to request clarification or add additional context in comments.

2 Comments

You mean data.results rather than data[results]
what is the difference between both dara.results and data['results']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.