JSON module
There was an eval function that could extract a corresponding data type from a string, such as "{" "Name": "Zhangsan"} "to extract a dictionary." JSON modules can do the same thing, but more powerful, Eval can only recognize the data structure of the Python language. JSON can recognize multi-language data structures
- Import of modules
Import JSON
- Encapsulates a data type in JSON format (string) with dumps
DIC = {"name":"codescrew"= json.dumps (DIC)
- Restores the JSON format to the original data type loads
DIC = Json.loads (DIC_STR)
- Encapsulate the data type in JSON format and write to the file using the dump
Dic_str = Json.dump (dic,filename)
- Read the JSON from the file and restore it, using the load
Json.load (filename)
Pickle Module
The use of pickle is exactly the same as the JSON module. The difference is that JSON is finally encapsulated in a string form, and pickle encapsulates the serialized object (byte type). Pickle modules can encapsulate more data types (functions, classes can also be encapsulated)
"Python standard library module four" JSON module and Pickle module learning