将字典转换为字符串并应用编
import json data = {name": "John”,"age”. "30"} json_str =json.dumps(data) # 将字典转换为json格式字符串 json_str.encode("utf-8") # 应用编码
字符串str转为字典dict
import json a = '{"a":"1", "b":"1"}' c=json.loads(a) print(c, type(c))
a = '{"a":"1", "b":"1"}' b = eval(a) print(b, type(b))