我一直在努力解决这个问题,但似乎无法正常工作。我可以通过在sqs轮询中指定“消息”来进行深入研究,但无法深入了解:
我正在检索AWS SQS消息:
{
'Messages': [
{
'MessageId': '37b13967-a92e-4b8b-8aef-32341a8e1e32',
'ReceiptHandle': 'xyz',
'MD5OfBody': '081f4bdad6fd3d53c88f165a884a39da',
'Body': '{"inputIDList":["1234","5678"],"eventID":"9337","scheduleEvent":false,"addToList":true,"listID":"7654","clientID":"123-ABC-456"}'
}
],
'ResponseMetadata': {
'RequestId': '79dafe96-04d9-5122-8b2a-a89b79a76a46',
'HTTPStatusCode': 200,
'HTTPHeaders': {
'x-amzn-requestid': '79dafe96-04d9-5122-8b2a-a89b79a76a46',
'date': 'Tue, 01 Oct 2019 16:13:50 GMT',
'content-type': 'text/xml',
'content-length': '4792'
},
'RetryAttempts': 0
}
}
哪个返回JSON响应:
'{"inputIDList":["1234","5678"],"eventID":"9337","scheduleEvent":false,"addToList":true,"listID":"7654","clientID":"123-ABC-456"}'
我在这里需要做的只是提取“ Body”的值,但是我不能在不出错的情况下进行足够深的挖掘。
我想返回的本质上就是JSON或字符串:
ThemeData
我对此非常陌生。任何帮助将不胜感激!
答案 0 :(得分:0)
您可以使用
获得所需的输出print (response['Messages'][0]['Body'])
答案 1 :(得分:0)
除了@matesio 的回答之外,如果您想将消息正文存储为 python 字典,只需将其用 json.loads 包装:
import json
message = json.loads(response['Messages'][0]['Body'])