【发布时间】:2019-11-27 10:07:42
【问题描述】:
有没有办法在 python 中处理 json 数据树。 假设我的 json 树看起来像这样:
"owner": {
"location": {
"longitude":"546561.65101",
"city":{
"zipcode":"546879",
"city":"Boston"
}}},
我的 python 脚本如下所示:
import json
with urlopen("example.com/example.json") as response:
source = response.read()
data=json.loads(source)
#lets say i want to extract specific json data with a for loop
for items in data:
city=items['HOW CAN I ACCESS THE CITY TAG WITHIN THE PARENT TAGS']
【问题讨论】:
-
因为这只是 json/字典数据,所以你可以使用 items.owner.location.city OR items['owner']['location']['city']
标签: python json for-loop web-scraping