Iterate over JSON Object using Python

前端 未结 2 1417
-上瘾入骨i
-上瘾入骨i 2021-01-26 02:10

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\": [
    {
             


        
2条回答
  •  执念已碎
    2021-01-26 02:18

    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']
    

提交回复
热议问题