我正在使用此查询获取一些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
$.getJSON(locationstring, function (result) {
console.log(result.results[0].formatted_address);
});
完整的代码,以获得您想要的东西。你不需要$.each
试试这个:
$.getJSON(locationstring, function (result) {
console.log(result.results[0].formatted_address);
});