json.dumps 与 json.loads 实例

import json # Python 字典类型转换为 JSON 对象 data = { ‘no’ : 1, ‘name’ : ‘Runoob’, ‘url’ : ‘http://www.runoob.com’ } json_str = json.dumps(data) print (“Python 原始数据:”, repr(data)) print (“JSON 对象:”, json_str)
执行以上代码输出结果为:

Python 原始数据: {'url': 'http://www.runoob.com', 'no': 1, 'name': 'Runoob'} JSON 对象: {"url": "http://www.runoob.com", "no": 1, "name": "Runoob"}