标签:结构 imp import 字符 indent word kong with name
json.loads() :对数据进行解码
# 写入 JSON 数据
with open('data.json', 'w') as f:
json.dump(data, f)
# 读取数据
with open('data.json', 'r') as f:
data = json.load(f)
json_data={}
with open('na.json','w',encoding='utf-8') as json_file:
json.dump(json_data,json_file,ensure_ascii=False)
print("json 文件保存成功! ")
import json
with open('na.json','r',encoding='utf-8') as json_file:
data=json.load(json_file)
print(data)
import json
def print_json():
js_data=open('na.json','r',encoding='utf-8')
js=json.load(js_data)
pretty_dict(js)
def pretty_dict(my_dict): #美观打印
#利用json的打印 友好打印字典等结构。备用
print(json.dumps(my_dict,ensure_ascii=False,indent=1))
if __name__=='__main__':
print_json()
标签:结构 imp import 字符 indent word kong with name
原文地址:https://www.cnblogs.com/shitou6/p/9456662.html