使用 jQuery 读取递归数组

read recursive array with jquery

本文关键字:数组 递归 读取 jQuery 使用      更新时间:2023-09-26

我有这个来自谷歌 API 的 json:

{
   "results" : [
      {
         "formatted_address" : "1 Broadway, New York, NY 10021, USA",
      }
   ],
   "status" : "OK"
}

如何获取"formatted_address"的值?

使用此代码(使用 jquery)我只得到"结果是数组"

$.getJSON(jsonFile, function(data){
    $.each(data, function(key, val){
        alert(key + ' is ' + val);
    });
});

在 php 中,这很容易,但我需要它是客户端的

$.getJSON(jsonFile, function(data) {
    $.each(data.results, function(key, val) {
        alert(key + ' is ' + val);
    });
});

这应该有效。