我有一个 JSON 对象,想知道如何遍历该对象以提取“id”的值。{"totalSize": 5,"done": true,"records": [ { "attributes": { "type": "EventLogFile", "url": "/services/data/v38.0/sobjects/EventLogFile/0AT1U000003kk7dWAA" }, "Id": "0AT1U000003kk7dWAA" }, { "attributes": { "type": "EventLogFile", "url": "/services/data/v38.0/sobjects/EventLogFile/0AT1U000003kk7eWAA" }, "Id": "0AT1U000003kk7eWAA" 我在下面尝试一些东西。sub_data = s["records"]["id"]for i in sub_data: print(sub_data['id'])
2 回答

慕工程0101907
TA贡献1887条经验 获得超5个赞
s = """{ "totalSize": 5,
"done": true, "records": [
{ "attributes": {
"type": "EventLogFile",
"url": "/services/data/v38.0/sobjects/EventLogFile/0AT1U000003kk7dWAA" },
"Id": "0AT1U000003kk7dWAA" }
]
}"""
s = json.loads(s)
[r['Id'] for r in s['records']]
['0AT1U000003kk7dWAA']
添加回答
举报
0/150
提交
取消