json module

 1 import json
 2 x="[null,true,false,1]"
 3 # print(eval(x))
 4 print(json.loads(x))
 5 import json
 6 l = [1,2,3]
 7 data_l = json.dumps(l)
 8 print(data_l)
 9 print(type(data_l))
10 
11 dic = {"name":"sttttt"}
12 f = open('json_test','w' )
 13 f.write(json.dumps(dic)) #Write       json into a dictionary of strings 
14  f.close()
 15  
16 f = open( ' json_test ' , ' r ' )
 17 data = json.loads (f.read()) #Convert    json to string dictionary back to dictionary 
18  print (data,type(data))
 19  
20 f = open( ' json_test ' , ' w ' )
 21 json.dump(dic, f)               # json.dump writes json into a string dictionary 
22  
23 f = open(' json_test ' , ' r ' )
 24 data = json.load(f)              # Convert json.dumo to a dictionary of strings and convert it back to a dictionary with json.load 
25  print (data,type(data))

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324862465&siteId=291194637