我正在尝试通过url编码的webhook接收数据。我用这两行解码了它:
txt = request.body
decoded = json.loads(dumps(repr(parse_qs(txt))))
我收到这个作为输出:
{
b'receiver':[
b'1216******8'
],
b'sender':[
b'1415******7'
],
b'message':[
b'Something new this time'
],
b'date':[
b'1499608381'
],
b'date_utc':[
b'1499622781'
],
b'reference':[
b'10273548605'
],
b'id':[
b'476b4fc1559626d7d5e5ac4b90888173'
],
b'message_id':[
b'7459df31559626d7d5cab31m07097860'
],
b'recipient':[
b'1216*****8'
],
b'originator':[
b'1415*****7'
],
b'body':[
b'Something new this time'
],
b'createdDatetime':[
b'2017-07-09T17:53:01+00:00'
]
}
我如何在Python中阅读?我已尝试按名称定义每个字段并获取错误
TypeError: string indices must be integers
但是当我尝试使用数字时(如下所示),我只得到输出的第一个,第二个,第三个字符。
UserText.objects.create(
id = decoded[0],
recipient = decoded[1],
originator = decoded[2],
body = decoded[3],
createdDatetime = decoded[4],
)