0

我在Google表格中使用JSON来查找Zip并找到该县。我只想让这个县回来。我可以得到它返回每个值,所以ImportJSON函数正在工作。过滤同名的JSON数据

这是我的公式。我尝试了所有参考的排列,但我不知道如何格式化它。

=ImportJSON(CONCATENATE("https://maps.googleapis.com/maps/api/geocode/json?address="92660), "results/address_components/long_name[3]", "noHeaders") 

以下是来自Google地图地理编码API的JSON数据。我只想要县名。在这个例子中,它是“橙县”。

{ 
     "results" : [ 
      { 
      "address_components" : [ 
       { 
        "long_name" : "92660", 
        "short_name" : "92660", 
        "types" : [ "postal_code" ] 
       }, 
       { 
        "long_name" : "Newport Beach", 
        "short_name" : "Newport Beach", 
        "types" : [ "locality", "political" ] 
       }, 
       { 
        "long_name" : "Orange County", 
        "short_name" : "Orange County", 
        "types" : [ "administrative_area_level_2", "political" ] 
       }, 
       { 
        "long_name" : "California", 
        "short_name" : "CA", 
        "types" : [ "administrative_area_level_1", "political" ] 
       }, 
       { 
        "long_name" : "United States", 
        "short_name" : "US", 
        "types" : [ "country", "political" ] 
       } 
      ], 
      "formatted_address" : "Newport Beach, CA 92660, USA", 
      "geometry" : { 
       "bounds" : { 
        "northeast" : { 
         "lat" : 33.671823, 
         "lng" : -117.841337 
        }, 
        "southwest" : { 
         "lat" : 33.6040739, 
         "lng" : -117.909447 
        } 
       }, 
       "location" : { 
        "lat" : 33.6301328, 
        "lng" : -117.8721676 
       }, 
       "location_type" : "APPROXIMATE", 
       "viewport" : { 
        "northeast" : { 
         "lat" : 33.671823, 
         "lng" : -117.841337 
        }, 
        "southwest" : { 
         "lat" : 33.6040739, 
         "lng" : -117.909447 
        } 
       } 
      }, 
      "place_id" : "ChIJRdSajSne3IAR8T4A2x-wgrE", 
      "types" : [ "postal_code" ] 
      } 
     ], 
     "status" : "OK" 
    } 

回答

2

有3个东西,是防止它正确导入:

  1. 特别是在连击功能,您有address="92660

这应该是address=",92660

,或者您可以消除CONCAT函数一起,并像这样格式化网址:

"https://maps.googleapis.com/maps/api/geocode/json?address="&"92660"

或技术上指向例如A1的单元格,其值为92660,例如, "https://maps.googleapis.com/maps/api/geocode/json?address="&A1

  • 丢失的初/results

  • 前为了得到第三项,而不是使用[3],包裹在公式中的指数函数和参考3

  • 完整的事指数:

    =index(importjson("https://maps.googleapis.com/maps/api/geocode/json?address="&A1,"/results/address_components/long_name","noHeaders"),3)

    enter image description here

    +0

    谢谢。这工作完美。事实证明,谷歌的地址并非全部相同,但这是另一个问题。 – Thomas

    0

    你不给很多细节,而是只解析JSON,然后做的结果[ “address_components”]什么[2] [ “LONG_NAME”]?

    +0

    当我这样做,我得到一个“公式解析错误。” '= ImportJSON(CONCATENATE(“https://maps.googleapis.com/maps/api/geocode/json?address=”,C2),“results [”address_components“] [2] [”long_name“]”,“如果我删除了引号,就会得到一个“Reference not found error”= ImportJSON(CONCATENATE(“https://maps.googleapis.com/maps/api/geocode/json?address=”,C2) ,“results [address_components] [2] [long_name]”,“noHeaders”) – Thomas