开发者

Help with jQuery grabbing json data

I am having some trouble here, my json data is outputting as follows:

{"date":[{"day_w":"Tuesday","day_n":"28","month":"Dec"}],"subscr开发者_JAVA百科iptions":[{"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?


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);


You can write data.date[0] to get the first object in the array.


Try this - http://jsfiddle.net/FloydPink/bAtEW/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜