从Python中的文件夹加载几个Json文件

时间:2016-04-26 09:26:18

标签: python json

我正在尝试从单独的导向器加载一组json文件,出现以便在加载它们时工作.jsonlist被加载并看起来像这样:

['recording0.json','recording1.json','recording2.json','recording3.json']

但是,当我想加载实际数据时,它告诉我没有要加载的json文件。我认为它与路径有关,但我不知道。这里有一个非常相似的问题,但答案似乎并不适合我。

for data in jsonlist:
    datafile = INPUT_DIR + data
    with open(datafile, 'r') as json_file:
        json_data = json_file.read()
        stamps_and_coordinates = json.loads(json_data)

“无法解码JSON对象”

编辑:我正在加载jsonlist:

filelist = [f for f in listdir(INPUT_DIR) if isfile(join(INPUT_DIR, f))]
jsonlist = []
 for i in filelist:
     if i.endswith('.json'):
         jsonlist.append(i)

令人难以置信的缩短json内容的版本示例如下:

[{"Timestamp":"1184134472","DeltaTime":"42147765","PerceptorStamp":"39.6890000000005","X":1182.913,"Y":677.6516},
{"Timestamp":"1184149377","DeltaTime":"42162670","PerceptorStamp":"39.7120000000006","X":1175.157,"Y":679.6996},
{"Timestamp":"1184162553","DeltaTime":"42175846","PerceptorStamp":"39.7120000000006","X":1193.353,"Y":671.6687}]

0 个答案:

没有答案