JSON serialization and JSON deserialization
#!/usr/bin/env Python3#-*-coding:utf-8-*-__author__='life into the play'ImportJsona= { "name":"Test", " Age":" -",}#JSON serializationWith open ("json_test","W", encoding="Utf-8") as F:f.write (Json.dumps (a))#equivalent to this json.dump (a,f)#JSON deserializationWith open ("json_test","R", encoding="Utf-8") as F:Print(Json.loads (F.read ()))#equivalent to this print (Json.load (f))
Pickle serialization and deserialization
#!/usr/bin/env Python3#-*-coding:utf-8-*-__author__='life into the play'ImportPickledefHello ():Print("hello!") return0a= { "name":"Test", " Age":" -", "func": Hello}with Open ("json_test","WB") as F:f.write (Pickle.dumps (a))#equivalent to this pickle.dump (a,f)With Open ("json_test","RB") as F:Print(Pickle.loads (F.read ()) ["func"]())#equivalent to this print (Pickle.load (f) ["Func"] ())
Python JSON and Pickle serialization