Two modules for serialization in Python
The JSON module provides four functions: dumps, dump, loads, load
The Pickle module provides four functions: dumps, dump, loads, load
Import jsons = ' {' key ': ' Value '} ' dic = Json.loads (s) str = json.dumps (DIC) print (Dic,type (DIC)) print (Str,type (str)) Result: {' Key ': ' Value '} <class ' Dict ' >{"key": "Value"} <class ' str ' >
If you are dealing with files instead of strings, you can use json.dump()
and json.load()
encode and decode JSON data. For example:
# Writing JSON datawith open (' Data.json ', ' W ') as F:json.dump (data, f) # Reading Data Backwith open (' Data.json ', ' R ') a s f:data = Json.load (f) Pickle used to convert between Python-specific type and Python base data type
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/82/7D/wKioL1dWy6HR6HYuAABUpCNKHV0201.png-wh_500x0-wm_3 -wmp_4-s_1907122844.png "title=" 425762-20151114231017087-842020084.png "alt=" Wkiol1dwy6hr6hyuaabupcnkhv0201.png-wh_50 "/>
Python json Pickle