Tag:ini Note obj file ext bsp convert string span
Json.dumps () is the conversion of a Python data structure into a JSON-encoded string json.loads () to convert a JSON-encoded string into a Python data structure the following:>>> Import json>>> a={' name ': ' Xiaoming '}>>> json.dumps (a) ' {' name ': ' Xiaoming '} ' >>> b= ' {' Name ":" Xiaoming "} ' >>> Json.loads (b) {u ' name ': U ' xiaoming '} Note: We originally defined the elements of a as single quotes, and dumps transformed into double quotes, When the loads becomes a Python variable, the elements become single quotes, and the string is added with a U. Then when I define the following string type, the element contents are in single quotes, and the entire string is enclosed in double quotes:>>> c= "{' name ': ' Xiaoming '}" >>> print Json.loads (c) Traceback (most recent): File "<stdin>", line 1, in <module>file "/usr/local/python27/lib/python2.7 /json/__init__.py ", line 339, in Loadsreturn _default_decoder.decode (s) File"/usr/local/python27/lib/python2.7/json/ decoder.py ", line 364, in decodeobj, end = Self.raw_decode (S, idx=_w (s, 0). End ()) File"/usr/local/python27/lib/python2.7 /json/decoder.py ", line 380, in raw_decodeobj, end = Self.scan_once (s, idx) valueerror:expecting property Name:line 1 col Umn 2 (char 1) program error, so General Requirements when a string is converted to a Python data type by loads, the outer layer is enclosed in single quotes, and the element key and value in double quotation marksAlso, even if the above conditions are met, when the Unicode with the U prefix is modified, the error:>>> c= ' {u ' name ": U" xiaoming "} ' >>> json.loads (c) Traceback ( Most recent call last): File "<stdin>", line 1, in <module>file "/usr/local/python27/lib/python2.7/json/__ init__.py ", line 339, in Loadsreturn _default_decoder.decode (s) File"/usr/local/python27/lib/python2.7/json/ decoder.py ", line 364, in decodeobj, end = Self.raw_decode (S, idx=_w (s, 0). End ()) File"/usr/local/python27/lib/python2.7 /json/decoder.py ", line 380, in raw_decodeobj, end = Self.scan_once (s, idx) valueerror:expecting property Name:line 1 col Umn 2 (char 1)so loads in the process, you also need to remove the u prefix modifier--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------
Python json dumps and loads may have made a mistake