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))

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM