有没有一种方法可以在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']
答案 0 :(得分:0)
x={
"owner": {
"location": {
"longitude":"546561.65101",
"city":{
"zipcode":"546879",
"city":"Boston"
}}}}
您可以使用
x['owner']['location']['city']['city']
这将输出为“波士顿”