列出JSON对象中的数据

问题描述 投票:-1回答:1

我正在尝试使用python从API提取数据。通过此代码,我试图在列表中打印字典的内容。

response = requests.get(url, params=payload)
data = response.json()
log = json.dumps(data['result'], indent = 1)
print log

到目前为止,它可以打印:

[
{
"line": "[email protected]:birthdaydate"
}, 
{
"line": "[email protected]:birthdaydate"
}, 
{
"line": "[email protected]:birthdaydate"
}, 
]

有没有一种方法可以使输出看起来像下面的样子?

"[email protected]:birthdaydate"
"[email protected]:birthdaydate"
"[email protected]:birthdaydate"
python json parsing output
1个回答
2
投票

尝试这个:

response = requests.get(url, params=payload)
data = response.json()
log = data['result']
for l in log:
    print(l["line"])
© www.soinside.com 2019 - 2024. All rights reserved.