我对python很陌生。除了我的以下代码之外,是否还有检查python中存在的特定JSON对象?承认我下面的代码不是很好的做法所以需要知道哪种方法更好检查和易于维护?
这是 JSON 响应:
[
{
"MessageId": "250e37a8-d779-48a1-9941-84219a82513e",
"ReceiptHandle": "AQEBjualXe2ywqTgIVmCNI5sKj7r48werf84HHA2BWZimwiEXLFxA/MiPBclK048NZBtOnM3dSDfoiwwqoNTPxTRz+IChd8McziweCxHX6texjAOi/MyAQjCWP+2hJPoxzQgXx9kjnKbepKlcgxhpOiQZe6WiSIq0dXwHHXSA7SP0g9NIR/dU38b+wmo0m2q7MNVfSct967EKF49wow9RHyFMO8iD8fH93PYT9om5NdUha3dvkWnisKcfuO5pZY3LLXPAnuZT/VfqxJjmPqb98iepBfqFb6SpM/02IVSql81XKJEbMBc4zPHp/Uace6e4UDGsn/hPCVsqQsTzrbKCR+ovpkhXipWwTYSlgsLe/o43k0UxhCN8eKhg835KuUkskA3T8C5Q6v6xgznlR7JJuhZpg==",
"MD5OfBody": "bbdc5fdb8be7251f5c910905db994bab",
"Body": "Information about current NY Times fiction bestseller for week of 12/11/2016.",
"Attributes": {
"SentTimestamp": "1553851566164"
},
"MD5OfMessageAttributes": "d25a6aea97eb8f585bfa92d314504a92",
"MessageAttributes": {
"Author": {
"StringValue": "John Grisham",
"DataType": "String"
},
"Title": {
"StringValue": "The Whistler",
"DataType": "String"
},
"WeeksOn": {
"StringValue": "6",
"DataType": "Number"
}
}
}
]
这是我要检查的python代码:
if 'Messages' in response:
message = response['Messages'][0]
receipt_handle = message['ReceiptHandle']
sqs.delete_message(
QueueUrl=queue_url,
ReceiptHandle=receipt_handle
)
print('Received and deleted message: %s' % message)
else:
print('Message not received yet')
请让我知道上面的代码是否是好的做法。
大话西游666
潇潇雨雨
慕后森
相关分类