我使用 telethon 包,用于连接和从电报获取数据。我想将 Message 对象转换为有效的 JSON。例如,我从 telethon 中的一个 API 获取此对象:
{
Message: {
via_bot_id: None,
entities: [],
out: None,
post: True,
from_id: None,
message: "hi everybody",
id: 71,
media_unread: None,
reply_markup: None,
fwd_from: {
channel_id: 1119999790,
channel_post: 2,
date: 2017 - 09 - 04 15: 43: 48,
from_id: None
},
reply_to_msg_id: None,
edit_date: None,
to_id: {
channel_id: 1099583379
},
views: 2,
mentioned: None,
date: 2017 - 09 - 05 09: 28: 46,
media: None,
silent: None
} }
这是我最喜欢的结果:
{
"Message": {
"via_bot_id": "None",
"entities": [],
"out": "None",
"post": "True",
"from_id": "None",
"message": "hi everybody",
"id": 71,
"media_unread": "None",
"reply_markup": "None",
"fwd_from": {
"channel_id": 1119999790,
"channel_post": 2,
"date": "2017 - 09 - 04 15: 43: 48",
"from_id": "None"
},
"reply_to_msg_id": "None",
"edit_date": "None",
"to_id": {
"channel_id": 1099583379
},
"views": 2,
"mentioned": "None",
"date": "2017 - 09 - 05 09: 28: 46",
"media": "None",
"silent": "None"
}}
有没有办法在 Python 中进行转换?