-1

抱歉,我是新手,不知道如何正确执行此操作。我想从中提取数据:

{
  "list": [
    { "brewery":"Strangeways", "beer":"Albino Monkey" },
    { "brewery":"St. Bernardus", "beer":"Pater 6" }
]
}

这就是我想出的

$(document).ready(function(){
    $.getJSON('http://example.com/api/temp/66', function(data) {
            var brewery=[];
        brewery[0]=data.list[0].brewery[1];
        var newHTML = [];
        $.each(brewery, function(index, value) {
                newHTML.push('<span>' + value + '</span>');
        });
        $(".element").html(newHTML.join(""));
    });

});
4

3 回答 3

1

怎么样

var brewery = JSON.parse(data);

然后,您可以像导航啤酒厂一样

brewery.list[0]
brewery.list[1]

等等..

于 2013-06-14T15:15:49.673 回答
0

啤酒厂的阵列data.list不在data.list[0],您也需要value.brewery在每个

    $.each(data.list, function(index, value) {
            newHTML.push('<span>' + value.brewery + '</span>');
            // or value.beer to get the beer string
    });
于 2013-06-14T15:15:43.417 回答
0
$(document).ready(function(){
    $.getJSON('http://example.com/api/temp/66', function(data) {
        $.each(data.list, function (index, value) {
            $(".element").append('<span>' + value.brewery + '</span>');
        });
    });
});
于 2013-06-14T15:19:52.603 回答