py3提取json指定内容_如何使用python从json中提取特定数据
我想提取下面给定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}$
更多推荐
所有评论(0)