我想提取下面给定json中“address_components”中的“long_name”数据。挑战是我只想要“long_name”数据,其“types”是“administrative_area_level_2”。请让我知道如何只提取特定的数据最好用python。谢谢

编辑:请注意,js[“results”][0][“address_components”][2][“long_name”]不是我想要提取它的值的方式,因为[“address_components”][2]会随着输入的不同位置而变化。我的主要标准是提取“long_name”的数据,其“types”总是“administrative_area_level_2”{

"status": "OK",

"results": [

{

"geometry": {

"location_type": "APPROXIMATE",

"bounds": {

"northeast": {

"lat": 12.9177876,

"lng": 80.24104

},

"southwest": {

"lat": 12.875989,

"lng": 80.20860669999999

}

},

"viewport": {

"northeast": {

"lat": 12.9177876,

"lng": 80.24104

},

"southwest": {

"lat": 12.875989,

"lng": 80.20860669999999

}

},

"location": {

"lat": 12.9009877,

"lng": 80.2279301

}

},

"formatted_address": "Sholinganallur, Chennai, Tamil Nadu, India",

"place_id": "ChIJGzh_3nlbUjoRGz_-itQtu_8",

"address_components": [

{

"long_name": "Sholinganallur",

"types": [

"sublocality_level_1",

"sublocality",

"political"

],

"short_name": "Sholinganallur"

},

{

"long_name": "Chennai",

"types": [

"locality",

"political"

],

"short_name": "Chennai"

},

{

"long_name": "Kanchipuram",

"types": [

"administrative_area_level_2",

"political"

],

"short_name": "Kanchipuram"

},

{

"long_name": "Tamil Nadu",

"types": [

"administrative_area_level_1",

"political"

],

"short_name": "TN"

},

{

"long_name": "India",

"types": [

"country",

"political"

],

"short_name": "IN"

}

],

"partial_match": true,

"types": [

"sublocality_level_1",

"sublocality",

"political"

]

}

]

}

下面是我正在尝试的代码,但我只得到输出位置。让我知道我需要对代码进行什么更改。在

^{pr2}$

GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e 4 个月前
8c391e04 6 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐