\\u559c\\u6b22\\u4e00\\u4e2a\\u4eba unicode编码问题

import json

from idna import unicode

# 方法1: json.loads()
msg1 = '{"msg": "\\u559c\\u6b22\\u4e00\\u4e2a\\u4eba"}'
# print(str())
print(json.loads(msg1))

# 方法2: 或者直接对value进行unicode编码
msg2 = '{"msg": "\\u8be5\\u7528\\u6237\\u5df2\\u6dfb\\u52a0\\u6863\\u6848,\\u8bf7\\u52ff\\u91cd\\u590d\\u6dfb\\u52a0"}'
print(unicode(eval(msg1)["msg"]))

# 逆向
msg3 = {"msg": "喜欢一个人"}
ret3 = json.dumps(msg3)  # ret3 就是 msg1
print(ret3, type(ret3))
发布了73 篇原创文章 · 获赞 14 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_42327755/article/details/102843229
今日推荐