Python JSON加载/转储破坏Unicode?

Python JSON加载/转储破坏Unicode?,python,json,unicode,Python,Json,Unicode,将包含unicode字符的字符串转储为json会产生奇怪的unicode转义序列: text = "⌂⚘いの法嫁" print(text) # output: ⌂⚘いの法嫁 import json json_text = json.dumps(text) print(json_text) # output: "\u2302\u2698\u3044\u306e\u6cd5\u5ac1" 我希望得到以下输出: "⌂⚘いの法嫁" 如何将unicode字符转储为字符而不是转义序列?使用调用确保as

将包含unicode字符的字符串转储为json会产生奇怪的unicode转义序列:

text = "⌂⚘いの法嫁"
print(text) # output: ⌂⚘いの法嫁

import json
json_text = json.dumps(text)
print(json_text) # output: "\u2302\u2698\u3044\u306e\u6cd5\u5ac1"
我希望得到以下输出:

"⌂⚘いの法嫁"
如何将unicode字符转储为字符而不是转义序列?

使用
调用确保ascii=False

json_string = json.dumps(json_dict, ensure_ascii=False)

在Python2上,返回值将是
unicode
,而不是
str
,因此您可能希望在对其进行任何其他操作之前对其进行
编码。

如何:json_string=unicode(r.text)它没有损坏
\u
四个十六进制数字是JSON中允许的Unicode字符表示形式。