Reputation: 12275
I am having some trouble here, my json data is outputting as follows:
{"date":[{"day_w":"Tuesday","day_n":"28","month":"Dec"}],"subscriptions":[{"subscribe":"example1"},{"subscribe":"example2"},{"subscribe":"example3"}]}
I am using the jQuery code:
$.getJSON("example.php",function(data){
$.each(data.subscriptions, function(i, item) {
var subscribeData = "<li>"+ item.subscribe +"</li>";
$('#list').append(subscribeData);
});
but I am having an issue grabbing the date array. I don't want to have to use .each because there is only one array holding the date. Does this make sense? Can anyone please help?
Upvotes: 1
Views: 133
Reputation: 14330
Why is date
an array at all? Why not just have the object in there directly?
{"date":{"day_w":"Tuesday","day_n":"28","month":"Dec"},"subscriptions":[...
If that's not an option, you can just access date[0]
:
doSomethingWith(data.date[0].day_w);
Upvotes: 1