Data conversion between python and json

import json

Python to json: json.dumps (obj)

json to python: json.loads (obj)

 

 

import json 

"" " 
           json python 
[]: Array list in json list    
{}: Object dictionary in json dict 
         true True 
         null None 
         false False 

" "" 

li = [11,22,33,44 , True, None]
 # Convert python data to json data 
res_1 = json.dumps (li)
 print (res_1, type (res_1)) 


dic = { " a " : 1, " b " : True, " c " :None}
res_2 = json.dumps(dic)
print(res_2,type(res_2))


# json转换为python

js1 = '{"a":true,"b":false}'
res3 = json.loads(js1)
print(res3,type(res3))

 

Guess you like

Origin www.cnblogs.com/erchun/p/12729201.html