天天看點

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)TypeError: the JSON object must be str, bytes or bytearray, not ‘TextIOWrapper’

TypeError: the JSON object must be str, bytes or bytearray, not ‘TextIOWrapper’

使用

json.loads()

時候遇到這個錯誤

解決辦法:

import json

with open(json_dir) as json_file:
     json_data = json.load(json_file)
           

網上也有說其他方法的,不過我都試了不行,上面的代碼才可以解決。