0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PythonでのJSON読み込みエラー JSONDecodeError

Posted at

環境 Windows10
Python3
Anaconda3

JSONファイルを読み込む為に以下のように記述しました。


import json
with open('file.json') as f:

file_keys = json.load(f)
しかし、以下のようなエラーが発生しました。

```
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-18-e6de140fc2b0> in <module>
      1 import json
      2 with open('file.json') as f:
----> 3     file_keys = json.load(f)

```
JSONファイルの構文をチェックしましたが、問題ない。
ググって、ググりまくっているうちに、どうも、コードの記述に間違えがあるような感じがする。
JSONファイルはこのコードと同じパスに入っているので、読み込んでくれるはず。
諦めて・・。
今度は、書き方を変えてみました。

import json

filename = "C:/Users/User/src/file.json"
with open(filename, "r", encoding="utf-8") as f:
file_keys = json.load(f)


無事、JSONファイルを読み込んでくれました。








0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?