If ensure_ascii is True (the default), all non-ASCII characters in the output are escaped with \uXXXX sequences, and the result is astrinstance consisting of ASCII characters only. Ifensure_ascii is False, some chunks written to fp may be unicode instances. This usually happens because the input contains unicode strings or theencoding parameter is used. Unless fp.write() explicitly understands unicode(as in codecs.getwriter()) this is likely to cause an error.


json dump有一个ensure_ascii参数,当它为True的时候,所有非ASCII码字符显示为\uXXXX序列,只需在dump时将ensure_ascii设置为False即可,此时存入json的中文即可正常显示。

例如:

json.dump(f, ensure_ascii=False)

GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e 4 个月前
8c391e04 7 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐