使用Python遍历JSON对象 [英] Iterate over JSON Object using Python
本文介绍了使用Python遍历JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JSON对象,想知道如何遍历该对象以提取"id"的值.
I have a JSON object and was wondering how I can iterate over the object to pull values for "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'])
推荐答案
您可以遍历records
键作为列表,然后访问每个子字典的Id
键:
You can iterate through the records
key as a list and then access the Id
key of each sub-dict:
for i in s["records"]:
print(i['Id'])
这篇关于使用Python遍历JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文