常用的json与其它数据类型进行转换的场景有:
import json
json.dumps(demo1)
json.loads(dem2)
# 对象转字符串
json_demo = {'name': 'code_space', 'size': '20cm'}
changed = json.dumps(json_demo)
print(type(changed))
print(changed)
-------------------------------------------
<class 'str'>
{"name": "code_space", "size": "20cm"}
# 字符串转json对象
str_demo = '''{"name": "code_space", "size": "20cm"}'''
changed = json.loads(str_demo)
print("取对象属性:"+changed["name"])
print(type(changed))
print(changed)
-------------------------------------------
<class 'dict'>
{'name': 'code_space', 'size': '20cm'}