What does serialization mean?
is to store the data in memory on the hard disk.
Why do I have to put the data in memory on the hard disk?
1. The program is running, shutting down, memory data loss.
2. The next time the program starts again, read back from the hard disk, or the original format, it is very good.
3. Most of the data in memory is in the form of nested dictionaries.
What is the point of extracting the memory data?
1. Share the memory data with other people through the network.
2. You can share data across platforms and across languages. Eg:c, Java, python
#1.json Usage#serialization of DumpsImportJsondata= {'K1': 123,'K2': 345}#serialize data to a stringD =json.dumps (data)Print(d, type (d))#serialize data into a string and deposit the filef = open ('Test.json','W') Json.dump (data, F)#turn a serialized string back into a dictionaryD2 =Json.loads (d)Print(d2['K1'])#serialize data into a string and deposit the filef = open ('Test.json','R') Data2=json.load (f)Print(Data2, type (DATA2))
Note: Dump can be written multiple times, but load can only be once . The JSON deserialization error is reported.
Python-json&pickle Module (serialization module)