gpt4 book ai didi

python - 如何在python中解析对象的JSON数组

转载 作者:行者123 更新时间:2023-12-03 22:53:41 27 4
gpt4 key购买 nike

我收到以下 JSON来自 POST 的数组回复 HTTP要求:

[{
"username": "username_1",
"first_name": "",
"last_name": "",
"roles": "system_admin system_user",
"locale": "en",
"delete_at": 0,
"update_at": 1511335509393,
"create_at": 1511335500662,
"auth_service": "",
"email": "userid_1@provider_1.com",
"auth_data": "",
"position": "",
"nickname": "",
"id": "short-string-of-random-characters-1"
}, {
...
}
<more such objects>..]

鉴于 typeof(response)给我 requests.models.Response ,我如何在 Python 中解析它?

最佳答案

看看json module .更具体地说是“解码 JSON:”部分。

import json
import requests

response = requests.get() # api call

users = json.loads(response.text)
for user in users:
print(user['id'])

关于python - 如何在python中解析对象的JSON数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48189684/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com