Python 解析文件中的多个JSON对象

Python 解析文件中的多个JSON对象,python,json,parsing,Python,Json,Parsing,我有一个JSON文件,其中包含以下内容 [ {"ID": 1, "timestamp": 10, "startingFloor": 1, "eventType": "enter"}, {"ID": 1, "timestamp": 10, "eventType": "call", "noOfCalls": 1}, {"ID": 1, "timestamp": 10, "startingFloor": 1, "eventType": "board"}, {"ID": 1, "timestamp

我有一个JSON文件,其中包含以下内容

[
{"ID": 1, "timestamp": 10, "startingFloor": 1, "eventType": "enter"}, 
{"ID": 1, "timestamp": 10, "eventType": "call", "noOfCalls": 1}, 
{"ID": 1, "timestamp": 10, "startingFloor": 1, "eventType": "board"}, 
{"ID": 1, "timestamp": 10, "eventType": "weight", "currentLoad": 53},
{"ID": 1, "timestamp": 36, "eventType": "call", "noOfCalls": 2},  
{"ID": 2, "timestamp": 50, "eventType": "call", "noOfCalls": 3}, 
{"ID": 2, "timestamp": 15, "eventType": "call", "noOfCalls": 1}, 
{"ID": 2, "timestamp": 38, "eventType": "weight", "currentLoad": 84},
{"ID": 2, "timestamp": 27, "eventType": "call", "noOfCalls": 2}, 
{"ID": 2, "timestamp": 36, "startingFloor": 2, "eventType": "enter"}, 
{"ID": 3, "timestamp": 50, "startingFloor": 3, "eventType": "enter"}, 
{"ID": 4, "timestamp": 38, "startingFloor": 4, "eventType": "board"}, 
{"ID": 4, "timestamp": 27, "startingFloor": 4, "eventType": "enter"},
{"ID": 5, "timestamp": 15, "startingFloor": 5, "eventType": "enter"}
]
我需要能够将此文件的每一行拉出,以类似于字典的方式与之交互(对于一个非常简单的示例,我需要找到最高的noOfCalls值)

问题是,该文件是一系列JSON对象,因此我以前使用的读取JSON文件的常规方法不起作用,例如

with open('input.json') as data_file:
    data = json.load(data_file)
我尝试过其他方法,例如尝试拉出每个对象并将其附加到列表中,例如:

data = []
for line in open('input.json','r'):
    data.append(json.loads(line))
但这一版本也不管用

我也尝试过其他各种方法,但最终总是出现错误,如“额外数据”、“预期值”等

如果您能提供有关从单个文件解析多个JSON对象的任何信息,我将不胜感激,并为没有更多的代码示例表示歉意,因为我尝试了很多次替换。请尝试以下方法:

with open('input.json') as data_file:
    data = json.loads(data_file.read())
似乎对我有用

    import json
    with open('input.json') as fr:
    data = json.loads(fr.read())

    for line in data:
        if 'noOfCalls' in line :
            print line['noOfCalls']

第一个代码片段与所提供的数据结合使用效果很好,JSON数据是一个包含多个字典的列表。你是说你的文件包含多个这样的列表吗?没关系,我是个十足的白痴。抛出额外的数据错误是由于一些我不认为是问题的评论。现在杀了我。