首页 > 解决方案 > 收到错误 json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)

问题描述

我通过我所做的简单 json 合并遇到了这个错误,不知道是什么导致它发生我使用的是 python 3.6

import glob
import json

result = []
for f in glob.glob("*.json"):
    with open(f, "rb") as infile:
        result.append(json.load(infile))

with open("merged_file.json", "wb") as outfile:
    json.dump(result, outfile)

我试图合并的示例 json

[{"player_id": 1, "year": "2013", "game_id": "201310200mia", "date": "2013-10-20", "game_number": "6", "age": "26.268", "team": "MIA", "game_location": "H", "opponent": "BUF", "game_won": false, "player_team_score": "21", "opponent_score": "23", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 1, "year": "2013", "game_id": "201310270nwe", "date": "2013-10-27", "game_number": "7", "age": "26.275", "team": "MIA", "game_location": "A", "opponent": "NWE", "game_won": false, "player_team_score": "17", "opponent_score": "27", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0.0, "defense_tackles": 1, "defense_tackle_assists": 2, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 1, "year": "2013", "game_id": "201310310mia", "date": "2013-10-31", "game_number": "8", "age": "26.279", "team": "MIA", "game_location": "H", "opponent": "CIN", "game_won": true, "player_team_score": "22", "opponent_score": "20", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 1, "year": "2013", "game_id": "201311110tam", "date": "2013-11-11", "game_number": "9", "age": "26.290", "team": "MIA", "game_location": "A", "opponent": "TAM", "game_won": false, "player_team_score": "19", "opponent_score": "22", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}]

还有一个(我需要组合超过 5000 个 json)

[{"player_id": 5, "year": "2015", "game_id": "201510110gnb", "date": "2015-10-11", "game_number": "5", "age": "24.298", "team": "GNB", "game_location": "H", "opponent": "STL", "game_won": true, "player_team_score": "24", "opponent_score": "10", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2015", "game_id": "201510180gnb", "date": "2015-10-18", "game_number": "6", "age": "24.305", "team": "GNB", "game_location": "H", "opponent": "SDG", "game_won": true, "player_team_score": "27", "opponent_score": "20", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 1, "kick_return_yards": 30, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2015", "game_id": "201511010den", "date": "2015-11-01", "game_number": "7", "age": "24.319", "team": "GNB", "game_location": "A", "opponent": "DEN", "game_won": false, "player_team_score": "10", "opponent_score": "29", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 1, "kick_return_yards": 22, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2015", "game_id": "201511150gnb", "date": "2015-11-15", "game_number": "9", "age": "24.333", "team": "GNB", "game_location": "H", "opponent": "DET", "game_won": false, "player_team_score": "16", "opponent_score": "18", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 7, "receiving_receptions": 4, "receiving_yards": 57, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2015", "game_id": "201512030det", "date": "2015-12-03", "game_number": "12", "age": "24.351", "team": "GNB", "game_location": "A", "opponent": "DET", "game_won": true, "player_team_score": "27", "opponent_score": "23", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 3, "receiving_receptions": 1, "receiving_yards": 16, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2015", "game_id": "201512130gnb", "date": "2015-12-13", "game_number": "13", "age": "24.361", "team": "GNB", "game_location": "H", "opponent": "DAL", "game_won": true, "player_team_score": "28", "opponent_score": "7", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 1, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2015", "game_id": "201512200rai", "date": "2015-12-20", "game_number": "14", "age": "25.003", "team": "GNB", "game_location": "A", "opponent": "OAK", "game_won": true, "player_team_score": "30", "opponent_score": "20", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 3, "receiving_receptions": 3, "receiving_yards": 33, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2015", "game_id": "201512270crd", "date": "2015-12-27", "game_number": "15", "age": "25.010", "team": "GNB", "game_location": "A", "opponent": "ARI", "game_won": false, "player_team_score": "8", "opponent_score": "38", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 2, "receiving_receptions": 1, "receiving_yards": 5, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2015", "game_id": "201601030gnb", "date": "2016-01-03", "game_number": "16", "age": "25.017", "team": "GNB", "game_location": "H", "opponent": "MIN", "game_won": false, "player_team_score": "13", "opponent_score": "20", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2015", "game_id": "201601100was", "date": "2016-01-10", "game_number": "17", "age": "25.024", "team": "GNB", "game_location": "A", "opponent": "WAS", "game_won": true, "player_team_score": "35", "opponent_score": "18", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 4, "receiving_receptions": 2, "receiving_yards": 14, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2015", "game_id": "201601160crd", "date": "2016-01-16", "game_number": "18", "age": "25.030", "team": "GNB", "game_location": "A", "opponent": "ARI", "game_won": false, "player_team_score": "20", "opponent_score": "26", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 12, "receiving_receptions": 4, "receiving_yards": 55, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2016", "game_id": "201609110jax", "date": "2016-09-11", "game_number": "1", "age": "25.269", "team": "GNB", "game_location": "A", "opponent": "JAX", "game_won": true, "player_team_score": "27", "opponent_score": "23", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 1, "receiving_receptions": 1, "receiving_yards": 8, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2016", "game_id": "201609180min", "date": "2016-09-18", "game_number": "2", "age": "25.276", "team": "GNB", "game_location": "A", "opponent": "MIN", "game_won": false, "player_team_score": "14", "opponent_score": "17", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2016", "game_id": "201609250gnb", "date": "2016-09-25", "game_number": "3", "age": "25.283", "team": "GNB", "game_location": "H", "opponent": "DET", "game_won": true, "player_team_score": "34", "opponent_score": "27", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2016", "game_id": "201610090gnb", "date": "2016-10-09", "game_number": "4", "age": "25.297", "team": "GNB", "game_location": "H", "opponent": "NYG", "game_won": true, "player_team_score": "23", "opponent_score": "16", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2016", "game_id": "201610160gnb", "date": "2016-10-16", "game_number": "5", "age": "25.304", "team": "GNB", "game_location": "H", "opponent": "DAL", "game_won": false, "player_team_score": "16", "opponent_score": "30", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 1, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2017", "game_id": "201709240det", "date": "2017-09-24", "game_number": "3", "age": "26.281", "team": "DET", "game_location": "H", "opponent": "ATL", "game_won": false, "player_team_score": "26", "opponent_score": "30", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2017", "game_id": "201710010min", "date": "2017-10-01", "game_number": "4", "age": "26.288", "team": "DET", "game_location": "A", "opponent": "MIN", "game_won": true, "player_team_score": "14", "opponent_score": "7", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2017", "game_id": "201710080det", "date": "2017-10-08", "game_number": "5", "age": "26.295", "team": "DET", "game_location": "H", "opponent": "CAR", "game_won": false, "player_team_score": "24", "opponent_score": "27", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 3, "receiving_receptions": 2, "receiving_yards": 37, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2017", "game_id": "201710150nor", "date": "2017-10-15", "game_number": "6", "age": "26.302", "team": "DET", "game_location": "A", "opponent": "NOR", "game_won": false, "player_team_score": "38", "opponent_score": "52", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 4, "receiving_receptions": 1, "receiving_yards": 7, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, "defense_safeties": 0, "point_after_attemps": 0, "point_after_makes": 0, "field_goal_attempts": 0, "field_goal_makes": 0, "punting_attempts": 0, "punting_yards": 0, "punting_blocked": 0}, {"player_id": 5, "year": "2017", "game_id": "201710290det", "date": "2017-10-29", "game_number": "7", "age": "26.316", "team": "DET", "game_location": "H", "opponent": "PIT", "game_won": false, "player_team_score": "15", "opponent_score": "20", "passing_attempts": 0, "passing_completions": 0, "passing_yards": 0, "passing_rating": 0, "passing_touchdowns": 0, "passing_interceptions": 0, "passing_sacks": 0, "passing_sacks_yards_lost": 0, "rushing_attempts": 0, "rushing_yards": 0, "rushing_touchdowns": 0, "receiving_targets": 0, "receiving_receptions": 0, "receiving_yards": 0, "receiving_touchdowns": 0, "kick_return_attempts": 0, "kick_return_yards": 0, "kick_return_touchdowns": 0, "punt_return_attempts": 0, "punt_return_yards": 0, "punt_return_touchdowns": 0, "defense_sacks": 0, "defense_tackles": 0, "defense_tackle_assists": 0, "defense_interceptions": 0, "defense_interception_yards": 0, "defense_interception_touchdowns": 0, }]

标签: python

解决方案


您的一个(或更多)JSON 文件格式不正确,并且您的代码缺少告诉您是哪一个所需的错误处理。

期望您手动运行所有 5000 个以查找错误是不合理的。因此,改为添加一些错误处理,其中包括异常消息中的文件名:

for f in glob.glob("*.json"):
    with open(f, "rb") as infile:
        try:
            result.append(json.load(infile))
        except json.decoder.JSONDecodeError as err:
            raise ValueError("JSON error decoding file '{0}': '{1}'".format(f, err))

如果有很多无效的 JSON 文件,您可以将 ; 替换raise ValueError("...")print("..."); 您的程序仍然无法处理这些文件,但至少会列出所有文件。


推荐阅读