在Python中转储到JSON时,会转义字符串中的Unicode值 [英] Unicode values in strings are escaped when dumping to JSON in Python

查看:106
本文介绍了在Python中转储到JSON时,会转义字符串中的Unicode值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

>>> print json.dumps('růže')
"r\u016f\u017ee"

(当然,在实际程序中,它不仅是单个字符串,而且在使用json.dump()时在文件中也像这样显示)我也希望它也输出简单的reže",如何这样做吗?

(Of course, in the real program it's not just a single string, and it also appears like this in the file, when using json.dump()) I'd like it to output simply "růže" as well, how to do that?

推荐答案

ensure_ascii=False参数传递给json.dumps:

Pass the ensure_ascii=False argument to json.dumps:

>>> print json.dumps('růže', ensure_ascii=False)
"růže"

这篇关于在Python中转储到JSON时,会转义字符串中的Unicode值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆