UserIsCorrupt
UserIsCorrupt

Reputation: 5025

Basic JSON parsing in jQuery

I'm very new to this, so could someone provide a really basic example?

Let's say the file located at http://www.example.org/test.json is this:

{
   "test":{
      "example":"Test",
      "another":"Text"
   },
   "blah":123
}

and the HTML is this:

<div id="whatever"></div>

How would I extract "Test" from the file and .append it in #whatever using jQuery?

Upvotes: -1

Views: 188

Answers (1)

Juan G. Hurtado
Juan G. Hurtado

Reputation: 2137

Try with:

$.getJSON('http://www.example.org/test.json', function(data) {
  $('#whatever').append(data.test.example);
});

Upvotes: 4

Related Questions