在python中读取json文件

时间:2016-07-13 11:06:27

标签: python json

嗨我想在python中读取一个JSON文件,我使用的任何语法都会收到错误而且我不知道该怎么做代码:

import urllib
import pprint
import json
import re
import requests
import pprint

with open('synsets.json' , encoding = 'utf-8') as json_data:
    d = json.loads(json_data.read())
    json_data.close()
    pprint(d) 

错误:

Traceback (most recent call last):
  File "D:\markaz\wikiomega\code1.py", line 13, in <module>
    d = json.loads(json_data.read())
  File "C:\Users\BehnaM1\AppData\Local\Programs\Python\Python35-32\lib\json\__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "C:\Users\BehnaM1\AppData\Local\Programs\Python\Python35-32\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\BehnaM1\AppData\Local\Programs\Python\Python35-32\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[Finished in 0.7s with exit code 1]

0 个答案:

没有答案