JSONDecodeError:预期值:第1行第1列(字符0)
我对Python比较陌生,不知道为什么会这样。我的数据集是一个JSON文件,其中包含有关YELP评论的信息
import json
import pandas as pd
readLimit = 1e3
def loadJSON(fileLocation):
data = []
with open(fileLocation) as file:
for index, line in enumerate(file):
if index > 1e3:
break
data.append(json.loads(line))
return pd.DataFrame(data)
data = loadJSON("yelp_dataset.json")
print(data.info())
JSONDecodeError Traceback (most recent call last)
<ipython-input-1-a8e79cea486a> in <module>
16 return pd.DataFrame(data)
17
---> 18 data = loadJSON("yelp_dataset.json")
19 print(data.info())
<ipython-input-1-a8e79cea486a> in loadJSON(fileLocation)
13 if index > 1e3:
14 break
---> 15 data.append(json.loads(line))
16 return pd.DataFrame(data)
17
~\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 parse_int is None and parse_float is None and
347 parse_constant is None and object_pairs_hook is None and not kw):
--> 348 return _default_decoder.decode(s)
349 if cls is None:
350 cls = JSONDecoder
~\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
~\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)