如何使用python提取JSON?

问题描述 投票:-2回答:1

我正在尝试提取json。我提取了错误的“错误”数据。当我尝试使用t3 = temp['errors'][0]时,我只会得到"Arg one must not be null or empty."

预期输出:

"Arg one must not be null or empty.",
"Arg two must not be null or empty."

这是我的json:

{
        "status": "Fail",
        "warnings": {
            "Code": "VALID",
            "Desc": "Invalid data",
            "errors": [
                "Arg one must not be null or empty.",
                "Arg two must not be null or empty."

            ]
        }
    }

这是我的代码:

tmp = json.loads(res.content)
print(tmp['status'])
temp = (tmp['warnings'])
t1 = temp['errorCode']
t2 = temp['errorDesc']
t3 = temp['errors'][0]
print(t1)
print(t2)
print(t3)

有人请纠正我我在做什么错?

python json
1个回答
0
投票

尝试:

t3 = temp['errors']
t3
# ['Arg one must not be null or empty.', 
# 'Arg two must not be null or empty.']
© www.soinside.com 2019 - 2024. All rights reserved.