我不明白为什么下面的类型从str变成了Unicode。
CASE1
所以,在第二种情况下,我们看到的是Unicode对象,而在第一种情况下,我们看到的是字符串。 我没有看到任何代码更改会导致这种情况。也许我错过了什么。 如果有任何线索,请告诉我。 谢谢
CASE1
Python 2.7 (r27:82500, Nov 19 2014, 18:07:42)
[GCC 4.5.1 20100924 (Red Hat 4.5.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> x = {'resources': {}, 'tags': ['a', 'b']}
>>> ret = json.dumps( x )
>>> ret
'{"resources": {}, "tags": ["a", "b"]}'
>>>
>>> type( ret )
<type 'str'>
>>> ret2 = json.loads( ret )
>>> ret2
{'resources': {}, 'tags': ['a', 'b']}
案例2
Python 2.7.5 (default, Apr 22 2015, 21:27:15)
[GCC 4.9.2 20141101 (Red Hat 4.9.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> x = {'resources': {}, 'tags': ['a', 'b']}
>>> ret = json.dumps( x )
>>> ret
'{"resources": {}, "tags": ["a", "b"]}'
>>> type( x )
<type 'dict'>
>>> type( ret )
<type 'str'>
>>> ret2 = json.loads( ret )
>>> ret2
{u'resources': {}, u'tags': [u'a', u'b']}
>>>
所以,在第二种情况下,我们看到的是Unicode对象,而在第一种情况下,我们看到的是字符串。 我没有看到任何代码更改会导致这种情况。也许我错过了什么。 如果有任何线索,请告诉我。 谢谢