python: json.dumps can't handle utf-8? -


below test program, including chinese character:

# -*- coding: utf-8 -*- import json  j = {"d":"中", "e":"a"} json = json.dumps(j, encoding="utf-8")  print json 

below result, json.dumps convert utf-8 original numbers!

{"e": "a", "d": "\u4e2d"} 

why broken? or wrong?

you should read json.org. complete json specification in white box on right.

there nothing wrong generated json. generators allowed genereate either utf-8 strings or plain ascii strings, characters escaped \uxxxx notation. in case, python json module decided escaping, , has escaped notation \u4e2d.

by way: conforming json interpreter correctly unescape sequence again , give actual character.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -