<------------json文件----------------->
{ "fontFamily": "微软雅黑", "fontSize": 12, "BaseSettings":{ "font":1, "size":2 } } <----------------读取代码------------------>
import json def read(): # 设置以utf-8解码模式读取文件,encoding参数必须设置,否则默认以gbk模式读取文件,当文件中包含中文时,会报错 f = open("test.json", encoding='utf-8') setting = json.load(f) # 注意多重结构的读取语法 family = setting['BaseSettings']['font'] style = setting['fontFamily'] print(family) print(style) if __name__=='__main__': read()