从JSON数组中获取第n个项目

问题描述 投票:-2回答:2

我正在使用此查询获取一些JSON数组数据:

$.getJSON(locationstring, function (result) {
    $.each(result, function (i, field) {
        console.log(result);
    });
});

它打印得像这样:

我需要在数组的第0个对象(或第1个)中获取标签“formatted_address”下的值,如图所示。我怎么能这样做?

这是为了从此链接获取第0个数组项的值“formatted_address”:http://maps.googleapis.com/maps/api/geocode/json?latlng=7.243286200000001,80.61632869999999&sensor=true

javascript jquery arrays json
2个回答
2
投票
$.getJSON(locationstring, function (result) { 
    console.log(result.results[0].formatted_address);
});

完整的代码,以获得您想要的东西。你不需要$.each


0
投票

试试这个:

$.getJSON(locationstring, function (result) {
    console.log(result.results[0].formatted_address);
});
© www.soinside.com 2019 - 2024. All rights reserved.