看一下2330.txt的結構
targetJson = r”C:\Python\Json\2330.txt”
import json
with open(targetJson,”r”) as f:
json_str = f.read()
jsn = json.loads(json_str)
print(jsn)
需要寫一個settings.json的檔案
import json
targetJson = r”C:\Python\Json\settings.json”
with open(targetJson, “r”) as f:
print(f,type(f))
json_str = f.read()
print(json_str,type(json_str))
jsonloads = json.loads(json_str)
print(jsonloads,type(jsonloads))
輸出結果:
settings.json:
{‘python.defaultInterpreterPath’: ‘D:\\myInstallation\\Python310\\python.exe’, ‘files.encoding’: ‘utf8’, ‘terminal.integrated.profiles.windows’: {‘Command Prompts’: {‘path’: [‘${env:windir}\\System32\\cmd.exe’], ‘args’: [], ‘icon’: ‘terminal-cmd’}}, ‘terminal.integrated.defaultProfile.windows’: ‘Command Prompts’, ‘editor.autoIndent’: ‘advanced’}