如何使用python解析JSON文件中的多个级别(数组)?

时间:2017-02-28 01:52:40

标签: python json

以下是我尝试在python中解析的示例JSON。 我很难解析"文件": 任何帮助表示赞赏。

{
    "startDate": "2016-02-19T08:19:30.764-0700",
    "endDate": "2016-02-19T08:20:19.058-07:00",
    "files": [
        {
            "createdOn": "2017-02-19T08:20:19.391-0700",
            "contentType": "text/plain",
            "type": "jpeg",
            "id": "Photoshop",
            "fileUri": "output.log"
        }
    ],
    "status": "OK",
    "linkToken": "-3418849688029673541",
    "subscriberViewers": [
        "null"
    ]
}

1 个答案:

答案 0 :(得分:1)

打印数组中每个文件的id

import json

data = json.loads(rawdata)                                                      

files = data['files']                                                           

for f in files:                                                              
    print(f['id'])