python与json的数据转换

import json

python转为json:json.dumps(obj)

json转为python:json.loads(obj)

import json

"""
           json                    python
[] :   json中的数组                列表 list   
{} :  json中的对象                字典dict
         true                       True
         null                       None
         false                      False

"""

li = [11,22,33,44,True,None]
# python数据 转换为json数据
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))
原文地址:https://www.cnblogs.com/erchun/p/12729201.html