如何在python中读取JSON文件?

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

标签: python json python-3.x

我正在尝试在python中读取json文件但无法执行此操作。我的json文件大小为436mb,我使用的是python 3.3.4版本 试过不同的方式

import json
from pprint import pprint
with open('drug-event-0002-of-0002.json') as data_file:    
    data = json.load(data_file)
print(data)

Error :
Traceback (most recent call last):
  File "C:/Users/533335/Desktop/jsonReadTest.py", line 6, in <module>
    print(data)
  File "C:\Python33\lib\idlelib\PyShell.py", line 1339, in write
    return self.shell.write(s, self.tags)
MemoryError

---------------------------------------------------------------------   
import ijson
with open('drug-event-0002-of-0002.json', 'r') as f:
    parser = ijson.parse(f)
    for prefix, event, value in parser:
        if prefix == "name":
            print(value)

Error :
Traceback (most recent call last):
  File "C:/Users/533335/Desktop/jsonReadTest.py", line 1, in <module>
    import ijson
ImportError: No module named 'ijson'

0 个答案:

没有答案