Why does json.dumps escape non-ascii characters with “\uxxxx”

后端 未结 3 1112
眼角桃花
眼角桃花 2020-12-10 21:37

In Python 2, the function json.dumps() will ensure that all non-ascii characters are escaped as \\uxxxx.

Python 2 Json

But isn\'t

3条回答
  •  一个人的身影
    2020-12-10 21:44

    That's exactly the point. You get a byte string back, not a Unicode string. Thus the Unicode characters need to be escaped to survive. The escaping is allowed by JSON and thus presents a safe way of representing Unicode characters.

提交回复
热议问题