gpt4 book ai didi

带有重音符号的 Python 转储 json

转载 作者:太空狗 更新时间:2023-10-29 21:26:34 25 4
gpt4 key购买 nike

<分区>

如何打印带有特殊字符如“à”或“ç”的 json?

我可以这样打印:

import json

weird_dict ={"person": "ç", "á": 'à', "ç": 'ã'}
print json.dumps(weird_dict, indent=4, sort_keys=True)

output:

{
"person": "\u00e7",
"\u00e1": "\u00e0",
"\u00e7": "\u00e3"
}

如果我使用'ensure_ascii=False'

weird_dict={"person": "ç", "á": 'à', "ç": 'ã'}
print json.dumps(weird_dict, indent=4, sort_keys=True, ensure_ascii=False)
output:
{
"person": "ç",
"á": "à",
"ç": "ã"
}

如何使用 json 克服特殊字符问题?当我使用 pystache 并尝试打印 pystache.render('Hi {{person}}!', weird_dict) 时,我需要渲染:

"'ascii' codec can't decode byte 0xc3 in position 4770: ordinal not in range(128)"

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com