python解析json响应

2024-04-23 20:36:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用一个JSON来解析一个JSON响应。在下面的例子中,我想知道如何检索'issueId':'executions':'id'的值?在下面的示例中,它是“8195”。。。。。在

r = requests.get(baseURL + getExecutionsForIssueId + id, auth=('user','pass'))
data = r.json()


JSON Response:
    {
        "status": {
            "1": {
                "id": 1,
                "color": "#75B000",
                "description": "Test was executed and passed successfully.",
                "name": "PASS"
             },
            "2": {
                "id": 2,
                "color": "#CC3300",
                "description": "Test was executed and failed.",
                "name": "FAIL"
            },
            "3": {
    .
    .
    .
        }
    },
    "issueId": 15825,
    "executions": [
        {
            "id": 8195,
            "orderId": 7635,
            "executionStatus": "-1",
            "comment": "",
            "htmlComment": "",
.
.
.

Tags: andnametestidjson示例getdescription
1条回答
网友
1楼 · 发布于 2024-04-23 20:36:13

您的JSON对象只是Python中的一个字典。访问您需要的值,如下所示:

data['executions']生成一个类似dictionary对象的数组,假设您的JSON响应是按预期键入的。在

executions = data['executions']
order_id = executions[0]['orderId']

如果您希望遍历它们以找到id为8195的正确对象:

^{pr2}$

相关问题 更多 >