JSON processing:
JSON is a data type that is common in all languages, like a dictionary in Python, and JSON is used with JSON modules, which have the following common methods: Key-value
Import JSON:
#dump/dumps Usage: both of the same points are translated into JSON strings, the difference is that the dump is converted into a JSON string after the dictionary is written to the file, such as: Json.dump (OBJ,FP)
One action is to convert "obj" to a JSON-formatted string, and one action is to write a string to a file, meaning that the file descriptor FP is a required parameter
DIC = {' name ': ' Liuchengsen ', ' Age ': 18}
Print (Json.dumps (DIC)) #把字典转换成json串
FW = open (' A.json ', ' W ')
res = Json.dump (DIC,FW) #把字段转换成json串并写入到文件中
#load/loads Usage: both of the same points convert the JSON string to a dictionary format, unlike load, which converts a JSON string in a file into a dictionary, such as Json.load ()
Serializes a readable file containing JSON-formatted data into a Python object
S_json = {"Name": "Liuchengsen", "Age": 18}
Print (Json.loads (S_json)) #把json串转换成字典
FR = Open (' A.json ', ' R ')
res = Json.load (FR) #从文件中读取json串 and converted to a dictionary
Python--json processing