用Python加载和解析包含多个JSON对象的JSON文件中加载和解析JSON文件Python..但我无法加载文件:import json
json_data = open('file')data = json.load(json_data)产量:ValueError: Extra data: line 2 column 1 - line 225116 column 1 (char 232 - 160128774)我看了看18.2. json-JSON编码器和解码器在Python文档中,但是阅读这个可怕的文档是相当令人沮丧的。前几行(用随机条目命名):{"votes": {"funny": 2, "useful": 5, "cool": 1}, "user_id": "harveydennis", "name": "Jasmine Graham", "url": "http://example.org/user_details?userid=harveydennis", "average_stars": 3.5, "review_count": 12, "type": "user"}{"votes": {"funny": 1, "useful": 2, "cool": 4}, "user_id": "njohnson", "name": "Zachary Ballard", "url": "https://www.example.com/user_details?userid=njohnson", "average_stars": 3.5, "review_count": 12, "type": "user"}{"votes": {"funny": 1, "useful": 0, "cool": 4}, "user_id": "david06", "name": "Jonathan George", "url": "https://example.com/user_details?userid=david06", "average_stars": 3.5, "review_count": 12, "type": "user"}{"votes": {"funny": 6, "useful": 5, "cool": 0}, "user_id": "santiagoerika", "name": "Amanda Taylor", "url": "https://www.example.com/user_details?userid=santiagoerika", "average_stars": 3.5, "review_count": 12, "type": "user"}{"votes": {"funny": 1, "useful": 8, "cool": 2}, "user_id": "rodriguezdennis", "name": "Jennifer Roach", "url": "http://www.example.com/user_details?userid=rodriguezdennis", "average_stars": 3.5, "review_count": 12, "type": "user"}
3 回答
临摹微笑
TA贡献1982条经验 获得超2个赞
import json data = []with open('file') as f: for line in f: data.append(json.loads(line))
波斯汪
TA贡献1811条经验 获得超4个赞
[
]
添加回答
举报
0/150
提交
取消