Json.dumps is the encoding parsing of a Python data type list in JSON format,
Examples are as follows:
>>> import JSON module in JSON #导入python
>>> L = [' Iplaypython ', [n/a], {' name ': ' Xiaoming '}] #创建一个l列表
>>> Encoded_json = Json.dumps (l) # List of L, JSON format encoding
>>> print repr (l)
>>> Print Encoded_json #输出结果
This allows us to convert a list object into a JSON-formatted encoding.
Decoding python JSON format, you can use the module's json.loads () function parsing method,
Examples are as follows:
>>> Decode_json = json.loads (Encoded_json)
>>> print Type (Decode_json) #查看一下解码后的对象类型
>>> Print Decode_json #输出结果
Decode python JSON format into Python data style
Json.dump and Json.dumps are very different, json.dump is mainly used to read and write JSON files, and Json.load functions in conjunction with.
Json.dump (X,F), X is an object, and F is a file object that can write a JSON string to a text file.
Import JSON
data = [{"A": "AAA", "B": "BBB", "C": [4,5,6, (]},33), ' Tantengvip ', True]
Data2 = json.dumps (data)
Print (DATA2)
f = open ('./tt.txt ', ' a ')
Json.dump (DATA2,F)
This generates a tt.txt file that holds the JSON-formatted data. The dumps also provides pritty print, formatted output. Json.load loading JSON format file The following is the JSON data read from the TXT file.
f = open ('./tt.txt ', ' R ')
hehe = Json.load (f)
Print (hehe)
Summarize:
Json.dumps:dict to Str json.dump is to save Python data as JSON
Json.loads:str turns into Dict json.load is to read JSON data
Transferred from: http://www.cnblogs.com/111testing/p/6032076.html
JSON--Dump load dumps loads simple comparison