我試圖在python中加載我的twit數據,但是出現了一些錯誤。以下是我加載數據的代碼。我附上錯誤信息。我猜測我的TwitData1.json數據有一些問題,所以需要處理......我不知道我該如何處理這個問題。先謝謝你。加載json文件時的ValueError(python)
import json, pprint
with open("TwitData1.json") as json_file:
json_data = json.load(json_file)
pprint(json_data)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-26-ba1a50c671e1> in <module>()
2
3 with open("TwitData1.json") as json_file:
----> 4 json_data = json.load(json_file)
5 json_data.close()
6 pprint(json_data)
C:\Users\Jay\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.1.1975.win-x86_64\lib\json\__init__.pyc in load(fp, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
288 parse_float=parse_float, parse_int=parse_int,
289 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook,
--> 290 **kw)
291
292
C:\Users\Jay\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.1.1975.win-x86_64\lib\json\__init__.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
336 parse_int is None and parse_float is None and
337 parse_constant is None and object_pairs_hook is None and not kw):
--> 338 return _default_decoder.decode(s)
339 if cls is None:
340 cls = JSONDecoder
C:\Users\Jay\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.1.1975.win-x86_64\lib\json\decoder.pyc in decode(self, s, _w)
366 end = _w(s, end).end()
367 if end != len(s):
--> 368 raise ValueError(errmsg("Extra data", s, end, len(s)))
369 return obj
370
ValueError: Extra data: line 2 column 1 - line 21 column 1 (char 2057 - 70650)
您應該嘗試通過驗證程序運行您的數據 - 錯誤消息表明數據不是有效的json。您可以嘗試[jq](http://stedolan.github.io/jq/)來執行此操作。 – vikramls 2014-11-24 05:33:57
非常感謝。我是一個蟒蛇相當新的人。這很有幫助。再次感謝你。 – Jihoon 2014-11-24 21:59:19