本文转自: 梁小白博客(http://biangbiang.cnblogs.com)
在使用json.dumps时要注意一个问题

    >>> import json
    >>> print json.dumps('中国')
    \u4e2d\u56fd

输出的会是
中国中的ascii 字符码,而不是真正的中文。
 
这是因为json.dumps 序列化时对中文默认使用的ascii编码.

想输出真正的中文需要指定ensure_ascii=False:

    >>> import json
    >>> print json.dumps('中国')
    "\u4e2d\u56fd"
    >>> print json.dumps('中国',ensure_ascii=False)
    中国

相关文章:

  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-02-27
  • 2021-08-19
  • 2022-12-23
猜你喜欢
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案