python - Why json.loads is returning a unicode object instead of string -
i cannot understand why following type changes unicode str.
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" 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']} case2
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" 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']} >>> so, in case 2 see unicode objects in case 1, see string instead. don't see code change has happened in 2 version of python can lead this. may missed something. leads appreciated. thanks
version 2.7 of python had bug caused behavior in first example. fixed in 2.7.5. see issue 10038. note version 2.6.6 behaves 2.7.5, indicating 2.7 behavior change previously-established behavior.
i don't think code change has happened in 2 version of python can lead this.
no need "think" nothing changed when can check , sure! every release of python comes extensive notes indicating changed. term "json" appears twenty-eight times in python 2.7.5 change log. changes have been made json in python 2.7.1, 2.7.2, 2.7.3, , 2.7.4, of course.
Comments
Post a Comment