First, the JSON format introduction
The JSON format is a lightweight data interchange format that is easily identifiable and machine-parsed, and its full name is called JavaScript Object Notation.
The JSON module provides an API interface similar to the Pickle Persistence module, which converts the in-memory Python object to a serialized representation, called JSON. JSON is the most widely used in AJAX applications in the communication between the Web server and the client, but also in the application of other programs.
Second, the JSON module encoding
Play Snake network Leo here using the Json.dumps method, a Python data type list is encoded in JSON format,
Examples are as follows:
>>> Import JSON #导入json格式
>>> L = [' Iplaypython ', [n/a], {' name ': ' Xiaoming '}] #创建一个l列表
>>> Encoded_json = Json.dumps (l) # List of L, JSON format encoding
>>> print repr (i)
>>> Print Encoded_json #输出结果
This allows us to convert a list object into a JSON-formatted encoding.
Third, the JSON module decoding
Decoding JSON format, you can use the Json.loads () function of this module to parse the method,
Examples are as follows:
>>> Decode_json = json.loads (Encoded_json)
>>> print Type (Decode_json) #查看一下解码后的对象类型
>>> Print Decode_json #输出结果
>>>
Python JSON module