将字典转换为 json 具有波斯语字符
Converting a dictionary to json having persian characters
这是我的一些代码,我正在尝试将字典转换为 json 具有波斯语字符,但我得到的是问号而不是字符。我的字典是这样的:
bycommunity("0": [{"60357": "این یک پیام است"}] )
with open('data.json', 'wb') as f:
f.write(json.dumps(bycommunity).encode("utf-8"))
结果是:
{"0": [{"60357": "?????? ??? ??? ???? ???????? ??????"}]}
data = {"0": [{"60357": "این یک پیام است"}]}
with open('data.json', 'w') as f:
json.dump(data, f, ensure_ascii=False)
并查看此 Answer 了解更多详情
with open(jsonFilePath, 'w', encoding='utf-8') as jsonf:
jsonf.write(json.dumps(data, ensure_ascii=False, indent=4))
这是我的一些代码,我正在尝试将字典转换为 json 具有波斯语字符,但我得到的是问号而不是字符。我的字典是这样的:
bycommunity("0": [{"60357": "این یک پیام است"}] )
with open('data.json', 'wb') as f:
f.write(json.dumps(bycommunity).encode("utf-8"))
结果是:
{"0": [{"60357": "?????? ??? ??? ???? ???????? ??????"}]}
data = {"0": [{"60357": "این یک پیام است"}]}
with open('data.json', 'w') as f:
json.dump(data, f, ensure_ascii=False)
并查看此 Answer 了解更多详情
with open(jsonFilePath, 'w', encoding='utf-8') as jsonf:
jsonf.write(json.dumps(data, ensure_ascii=False, indent=4))