【发布时间】:2016-08-14 14:46:53
【问题描述】:
这里是 Python 新手
我正在查询一个 API 并得到一个这样的 json 字符串:
{
"human": [
{
"h": 310,
"prob": 0.9588886499404907,
"w": 457,
"x": 487,
"y": 1053
},
{
"h": 283,
"prob": 0.8738606572151184,
"w": 455,
"x": 1078,
"y": 1074
},
{
"h": 216,
"prob": 0.8639854788780212,
"w": 414,
"x": 1744,
"y": 1159
},
{
"h": 292,
"prob": 0.7896996736526489,
"w": 442,
"x": 2296,
"y": 1088
}
]
}
我想出了如何在 python 中获取 dict 对象
json_data = json.loads(response.text)
但我不确定如何遍历 dict 对象。这个我试过了,但是这样反复打印出key,怎么访问父对象和子对象呢?
for data in json_data:
print data
for sub in data:
print sub
【问题讨论】:
标签: python json rest dictionary