Wu Yuxiong - born naturally PYTHON3 development of learning: JSON parsing data

Import JSON 
 
# the Python dictionaries objects into a JSON 
Data = {
     ' NO ' :. 1 ,
     ' name ' : ' Runoob ' ,
     ' URL ' : ' http://www.runoob.com ' 
} 
 
json_str = json.dumps (Data )
 Print ( " the Python raw data: " , the repr (data))
 Print ( " the JSON Object: " , json_str)
Import JSON 
 
# the Python JSON object type to dictionary 
DATAl = {
     ' NO ' :. 1 ,
     ' name ' : ' Runoob ' ,
     ' URL ' : ' http://www.runoob.com ' 
} 
 
json_str = json.dumps (DATAl )
 Print ( " Python raw data: " , the repr (DATAl))
 Print ( " JSON object: " , json_str) 
 
# convert JSON Python dictionary object 
data2 = json.loads(json_str)
print ("data2['name']: ", data2['name'])
print ("data2['url']: ", data2['url'])
# Write JSON data 
with Open ( ' the data.json ' , ' W ' ) AS F: 
    The json.dump (Data, F) 
 
# read data 
with Open ( ' the data.json ' , ' R & lt ' ) AS F: 
    Data = json.load (f)

 

Guess you like

Origin www.cnblogs.com/tszr/p/10965766.html