# -*- coding: UTF-8 -*- # json.dumps(): 对数据进行编码。 # json.loads(): 对数据进行解码。 import json info = [ '{"server1_name":"1","info1"}', '{"server2_name":"2","info2"}', ] json.dumps(info) #======================= python字典转化为 json 对象 =========================# 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) #======================= 将 JSON 对象转换为 Python 字典 =========================# python_dict = json.loads(json_str) print(python_dict)