Nick
Nick

Reputation: 55

Get value from JSON Array

My JSON currently looks like this:

 {
  "overview" : {
    "title" : "Blog"
  },

  "item" : {
    "title" : "Hello World"
  }

 }

My jQuery looks like this:

<script type="text/javascript">

$(document).ready(function(){

      $.getJSON(url, function(obj) {

        $.each(obj, function(key, value){

          $('.image-slide-title').append(value.title);

        });

      });

});

</script>

All works perfectly fine except the HTML markup is showing:

<div class="image-slide-title">Blog Hello World</div>

I just want it to skip the overview key/value and just go right to the item key/value so at the end of the day it looks like:

 <div class="image-slide-title">Hello World</div>

Upvotes: 0

Views: 1915

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

You could then loop through the obj.item properties:

for (var prop in obj.item) {
   var value = obj.item[prop];
   $('.image-slide-title').append(value);
}

Upvotes: 3

Related Questions