- Json.dumps ()
- Json.loads ()
- Json.dump
- Json.load
First, Json.dumps ()
Convert a Python dictionary type to a JSON object
Import json# Python dictionary type converted to JSON object data = { ' no ': 1, ' name ': ' Runoob ', ' url ': ' Http://www.runoob.com '}json_ str = json.dumps (data) print ("Python raw Data:", repr (data)) print ("JSON object:", Json_str)
Second, json.loads ()
Convert a JSON object into a python dictionary
# convert JSON object to Python dictionary data2 = json.loads (json_str) print ("data2[' name ']:", data2[' name ']) print ("data2[' url ']:", data2 [' URL '])
Third, Json.dump
Writes a serialized string to a file
Iv. Json.load
Read the contents of a file from a file
#然后来介绍dump方法 # import json# d1 = {' name ': ' Foot '} #这一步就会把d1做序列化处理后的字符串写到db这个文件中 # Json.dump (D1,open (' db ', ' W ')) # D1 = Json.load (Open (' db ', ' R ')) # print (D1,type (D1)) # {' Name ': ' Foot '} <class ' Dict ' >
The use of JSON modules for Python interface testing