Json.dumps is the encoding parsing of a Python data type list in JSON format,
Examples are as follows:
Import # import JSON modules in Python # Create an L list # A list of L, JSON format encoding Print repr (L) Print # Output Results
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# Look at the decoded object type Print# Output Results
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.
ImportJsondata= [{"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'= 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
Python note-dumps () and the use of loads ()