22
21

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 5 years have passed since last update.

PythonでJsonをよむときにエラーが出た場合の対処

Posted at

かなり手こずったのでメモメモ

エラー内容


Expecting value: line 1 column 1 (char 0)

対処

try~を入れてあげると解決しました〜


// ホームページからデーターをとってくる
jsons  = urlopen(url).read().decode('utf-8').split('\n')

result = []
for v in jsons :
    try:
        js = json.loads(v)
        result.append( js['info'] )
    except Exception:
        pass

追記 2017/02/13

下記でいけました〜

結局jsonデーターでない空の行が含まれてました

json_lines = [ json.loads(s) for s in responses if s != "" ]
22
21
2

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
22
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?