Python如何讀取json檔?codebeautify.org 線上瀏覽json檔, with open(targetJson,”r”) as f:     json_str = f.read()  ;   jsn = json.loads(json_str)

加入好友
加入社群
Python如何讀取json檔?codebeautify.org 線上瀏覽json檔, with open(targetJson,"r") as f:     json_str = f.read()  ;   jsn = json.loads(json_str) - 儲蓄保險王

看一下2330.txt的結構

Python如何讀取json檔?codebeautify.org 線上瀏覽json檔, with open(targetJson,"r") as f:     json_str = f.read()  ;   jsn = json.loads(json_str) - 儲蓄保險王

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)
   

Python如何讀取json檔?codebeautify.org 線上瀏覽json檔, with open(targetJson,"r") as f:     json_str = f.read()  ;   jsn = json.loads(json_str) - 儲蓄保險王

 

Visual Studio Code出現找不到指定模組錯誤

需要寫一個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))
   
Python如何讀取json檔?codebeautify.org 線上瀏覽json檔, with open(targetJson,"r") as f:     json_str = f.read()  ;   jsn = json.loads(json_str) - 儲蓄保險王
輸出結果:

Python如何讀取json檔?codebeautify.org 線上瀏覽json檔, with open(targetJson,"r") as f:     json_str = f.read()  ;   jsn = json.loads(json_str) - 儲蓄保險王

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’}

 

加入好友
加入社群
Python如何讀取json檔?codebeautify.org 線上瀏覽json檔, with open(targetJson,"r") as f:     json_str = f.read()  ;   jsn = json.loads(json_str) - 儲蓄保險王

儲蓄保險王

儲蓄險是板主最喜愛的儲蓄工具,最喜愛的投資理財工具則是ETF,最喜愛的省錢工具則是信用卡

You may also like...

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *