(这个问题与这个有关)
看看以下会话:
Python 2.7.3 (default, Jan 2 2013, 16:53:07)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import simplejson as json
>>>
>>> my_json = '''[
... {
... "id" : "normal",
... "txt" : "This is a normal entry"
... },
... {
... "id" : "αβγδ",
... "txt" : "This is a unicode entry"
... }
... ]'''
>>>
>>> cache = json.loads(my_json, encoding='utf-8')
>>>
>>> cache
[{'txt': 'This is a normal entry', 'id': 'normal'}, {'txt': 'This is a unicode entry', 'id': u'\u03b1\u03b2\u03b3\u03b4'}]
为什么 json 解码器有时会生成 unicode,有时会生成纯字符串?它不应该总是产生unicode吗?