The dumps () function, the loads () function, the dump () function, the load () function are mainly in the JSON module.
JSON returns a string type with high readability, which differs from pickle.
There are limitations, no serialization of time formats, etc., pickle can serialize data in any format, but Python-specific, JSON supports multiple languages.
#json. Dumps (' object ') #序列化对象, return string type
#json. Dump (' object ', f) #序列化对象到文件中
#json. Loads (' object ') #反序列化对象
#json. Load (f) #从文件中反序列对象, return to the original object
Import jsonobj = 123, "Abcdedf", ["AC", 123],{"key": "Value", "Key1": "Value1"} #json. Dumps (' object ') #序列化对象, Returns a string of type #json.dump (' object ', f) #序列化对象到文件中 #json.loads (' object ') #反序列化对象 #json.load (f) #从文件中反序列对象, Returns the original OBJECTR1 = Json.dumps (obj) print (r1) r2 = json.loads (r1) print (R2) with open (' db ', ' W ') as F: json.dump (obj, f) With open (' db ', ' R ') as F: r3 = Json.load (f) print (R3)
Python JSON module