Python json

原文:https://www.runoob.com/python3/python3-json.html

import json

data1 = {
    'no' : 1,
    'name' : 'Runoob',
    'url' : 'http://www.runoob.com'
}


# 对象 转换为 字符串
json_str = json.dumps(data1)


# 将json数据写入到文本
with open('data.json', 'w') as f:
    json.dump(json_str, f)


# 从文本中读取json数据
data2={}
with open('data.json', 'r') as f:
    data2 = json.load(f)
print(data2)
原文地址:https://www.cnblogs.com/guxingy/p/12372211.html