Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何将有效负载转换为人类可重新定义的形式_Python 3.x_Facebook_Chat_Messenger - Fatal编程技术网

Python 3.x 如何将有效负载转换为人类可重新定义的形式

Python 3.x 如何将有效负载转换为人类可重新定义的形式,python-3.x,facebook,chat,messenger,Python 3.x,Facebook,Chat,Messenger,我一直在用fbchat编写一个程序,发现一个有趣的函数吸引了我 class listen(fbchat.Client): def onMessageUnsent( self, mid=None, author_id=None, thread_id=None, thread_type=None, ts=None, msg=None, ): print(ms

我一直在用fbchat编写一个程序,发现一个有趣的函数吸引了我

class listen(fbchat.Client):
    def onMessageUnsent(
        self,
        mid=None,
        author_id=None,
        thread_id=None,
        thread_type=None,
        ts=None,
        msg=None,
    ):
        print(msg)
    

client = listen('','',session_cookies=cookies)
client.listen()

它给出了以下输出,但是我如何将它转换成人类可重绘的形式

{'payload': [123, 34, 100, 101, 108, 116, 97, 115, 34, 58, 91, 123, 34, 100, 101, 108, 116, 97,
 82, 101, 99, 97, 108, 108, 77, 101, 115, 115, 97, 103, 101, 68, 97, 116, 97, 34, 58, 123, 34,
 116, 104, 114, 101, 97, 100, 75, 101, 121, 34, 58, 123, 34, 111, 116, 104, 101, 114, 85, 115,
 101, 114, 70, 98, 73, 100, 34, 58, 49, 48, 48, 48, 52, 52, 53, 55, 50, 49, 57, 50, 57, 48, 54, 
125, 44, 34, 109, 101, 115, 115, 97, 103, 101, 73, 68, 34, 58, 34, 109, 105, 100, 46, 36, 99, 
65, 65, 66, 97, 95, 88, 69, 118, 56, 73, 112, 55, 121, 77, 120, 76, 114, 86, 49, 109, 100, 87,
 85, 49, 112, 48, 70, 108, 34, 44, 34, 100, 101, 108, 101, 116, 105, 111, 110, 84, 105, 109, 
101, 115, 116, 97, 109, 112, 34, 58, 49, 54, 48, 52, 54, 51, 55, 48, 57, 54, 53, 54, 56, 44, 34,
 115, 101, 110, 100, 101, 114, 73, 68, 34, 58, 49, 48, 48, 48, 52, 52, 53, 55, 50, 49, 57, 50, 
57, 48, 54, 44, 34, 109, 101, 115, 115, 97, 103, 101, 84, 105, 109, 101, 115, 116, 97, 109, 112,
 34, 58, 48, 125, 125, 93, 125], 'class': 'ClientPayload'}

这到底是什么意思。。。?

这不是base64或十六进制…

而是ASCII代码列表。试试这个:

"".join(map(chr, msg["payload"]))
结果是:

'{"deltas":[{"deltaRecallMessageData":{"threadKey":{"otherUserFbId":100044572192906},"messageID":"mid.$cAABa_XEv8Ip7yMxLrV1mdWU1p0Fl","deletionTimestamp":1604637096568,"senderID":100044572192906,"messageTimestamp":0}}]}'
它看起来像一个JSON字符串,可以使用
JSON.loads(…)
进行解析,例如:

import json
import pprint

# Fetch msg here using the code in the question body 

json_string = "".join(map(chr, msg["payload"]))
d = json.loads(json_string)
pprint.pprint(d)

你能不能说清楚一点,因为我是初学者。。。?简单地编写print(“.join(map(chr,payload)))不起作用…@CHD Ok,添加了一个可运行的示例。