簡體   English   中英

從 JSON 數組中獲取第 n 個項目

[英]Get the nth item from a JSON Array

我使用此查詢獲取一些 JSON 數組數據:

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

它會像這樣打印:

在此處輸入圖片說明

我需要在數組的第 0 個對象(或第一個)中獲取標記“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);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM