过滤 JSON 条同名数据
Filtering JSON data with the same name
我在 Google 表格中使用 JSON 来查找 Zip 并查找县。我只想要县 returned。我可以将它设为 return 每个值,以便 ImportJSON 函数正常工作。
这是我的公式。我已经尝试了参考文献的所有排列,但我只是不知道如何格式化它。
=ImportJSON(CONCATENATE("https://maps.googleapis.com/maps/api/geocode/json?address="92660), "results/address_components/long_name[3]", "noHeaders")
这是来自 Google 地图地理编码 API 的 JSON 数据。我只想要县长名称。在此示例中,它是 "Orange County"。
{
"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"
}
你没有给出很多细节,但是只解析 json,然后做结果如何["address_components"][2]["long_name"]?
有 3 个因素阻止它正确导入:
- 特别是在连接函数中你有
address="92660
应该是address=",92660
或者您可以完全删除 concat 函数并像这样格式化 url:
"https://maps.googleapis.com/maps/api/geocode/json?address="&"92660"
或技术上指向具有 92660
值的单元格,例如 A1,例如"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)
我在 Google 表格中使用 JSON 来查找 Zip 并查找县。我只想要县 returned。我可以将它设为 return 每个值,以便 ImportJSON 函数正常工作。
这是我的公式。我已经尝试了参考文献的所有排列,但我只是不知道如何格式化它。
=ImportJSON(CONCATENATE("https://maps.googleapis.com/maps/api/geocode/json?address="92660), "results/address_components/long_name[3]", "noHeaders")
这是来自 Google 地图地理编码 API 的 JSON 数据。我只想要县长名称。在此示例中,它是 "Orange County"。
{
"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"
}
你没有给出很多细节,但是只解析 json,然后做结果如何["address_components"][2]["long_name"]?
有 3 个因素阻止它正确导入:
- 特别是在连接函数中你有
address="92660
应该是address=",92660
或者您可以完全删除 concat 函数并像这样格式化 url:
"https://maps.googleapis.com/maps/api/geocode/json?address="&"92660"
或技术上指向具有 92660
值的单元格,例如 A1,例如"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)