[英]check the boolean value of json Python
您好,我是 AWS 和 SF 的新手,我正在尝试发送信息,我需要检查 json 的列表,我正在检查信息。 我有 next.json 列表:
here...b'[{
"id": "xxxx",
"success": true,
"errors": []
},
{
"id": "yyyy",
"success": true,
"errors": []
}
]'
在我的 lambda 中,我进行下一项检查:
response = requests.request("PATCH", url, headers=headers, data=body)
print('here...'+str(response.content))
if response.status_code == 200:
for iResult in response.content.b["success"]:
if iResult["success"] == false:
raise Exception('Error. Check SF size fields...')
我想确保每个 json 中的每个“成功”都等于 True。 如果引发异常是错误的。 所以我做了一个循环来遍历每个 json 但我遇到的问题是我不知道如何正确访问 json。 令我困惑的是我打印的 json 中的“b”。 有人能帮帮我吗? 谢谢
开头的b
表示您有字节,而不是字符串,这意味着您首先必须将响应内容转换为字典(想想 json 的 python 术语),以便您可以通过它们的键访问响应中的数据. 幸运的是,这很容易从请求响应中获得
json_data = response.json()
for sub_dict in json_data:
if sub_dict ["success"] is False:
raise ValueError("Check SF size fields...")
有关 requests.response 的更多信息: https://requests.readthedocs.io/en/latest/api/#requests.Response
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.