import json
dist = {"name":"IPhone","price":5800}
将字典对象转换为json字符串
jsonStr = json.dumps(dist)
print(type(jsonStr))
将列表对象转换为json字符串
list = [{"name":"IPhone","price":5800},{"name":"HuaWei","price":5300},{"name":"XiaoMi","price":3500}]
jsonStr2 = json.dumps(list)
print(type(jsonStr2))
distStr = '{"name":"IPhone","price":5800}'
将json字符串转换为字典对象
distResult = json.loads(distStr)
print(type(distResult))
listStr ='[{"name":"IPhone","price":5800},{"name":"HuaWei","price":5300}]'
listResult = json.loads(listStr)
print(type(listResult))