{"record":{"id":"c664fab4844f26c9","repo":"babalae/better-genshin-impact","slug":"json-c664fa","errorCode":null,"errorMessage":"JSON 战斗策略反序列化失败","messagePattern":"JSON 战斗策略反序列化失败","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/AutoFight/Script/JsonCombatStrategyParser.cs","lineNumber":57,"sourceCode":"    /// <returns>解析后的战斗策略</returns>\n    /// <exception cref=\"InvalidOperationException\">解析失败或格式错误</exception>\n    public static JsonCombatStrategy Parse(string json)\n    {\n        JsonCombatStrategy? strategy;\n        try\n        {\n            strategy = JsonConvert.DeserializeObject<JsonCombatStrategy>(json);\n        }\n        catch (JsonException ex)\n        {\n            Logger.LogError(\"JSON 战斗策略解析失败：{Msg}\", ex.Message);\n            throw new InvalidOperationException($\"JSON 战斗策略格式错误：{ex.Message}\", ex);\n        }\n\n        if (strategy == null)\n        {\n            Logger.LogError(\"JSON 战斗策略反序列化结果为空\");\n            throw new InvalidOperationException(\"JSON 战斗策略反序列化失败\");\n        }\n\n        if (strategy.Info == null)\n        {\n            Logger.LogError(\"JSON 战斗策略缺少 Info 节点\");\n            throw new InvalidOperationException(\"JSON 战斗策略缺少 Info 节点\");\n        }\n\n        if (strategy.Actions == null || strategy.Actions.Count == 0)\n        {\n            Logger.LogError(\"JSON 战斗策略缺少 Actions 节点或动作为空\");\n            throw new InvalidOperationException(\"JSON 战斗策略中未定义任何动作\");\n        }\n\n        // 校验动作合法性（名称需能作为条件标识符解析；index 允许重复）\n        ValidateActions(strategy.Actions);\n\n        Logger.LogInformation(\"JSON 战斗策略加载完成：{Name}，共 {Count} 个动作\",","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/AutoFight/Script/JsonCombatStrategyParser.cs#L39-L75","documentation":"Thrown by JsonCombatStrategyParser.Parse when JsonConvert.DeserializeObject returns null. This happens when the JSON content is literally the token 'null', or when the JSON structure deserializes to a null reference for the JsonCombatStrategy type (e.g., an empty object that maps to all-default-null properties).","triggerScenarios":"The JSON file contains just `null` as its root value, or the content is structurally empty/whitespace in a way that Newtonsoft maps to null. This is distinct from a JsonException (syntactically valid but semantically null).","commonSituations":"User accidentally saves a file containing 'null', an empty response from a download, or a file that was cleared but not properly rewritten. Could also occur if the JSON root is an array or primitive instead of an object (type mismatch causing null).","solutions":["Check that the JSON file contains a valid JSON object with 'Info' and 'Actions' properties.","Ensure the file is not empty or containing just 'null'.","Verify the root element is an object ({...}), not an array or primitive.","Re-download or recreate the strategy file from a known-good template."],"exampleFix":"// before (file content is just null)\nnull\n\n// after\n{\n  \"Info\": { \"Name\": \"MyStrategy\" },\n  \"Actions\": [ { \"Name\": \"start\", \"Index\": 1 } ]\n}","handlingStrategy":"validation","validationCode":"// Check for null-content edge cases before parsing\nvar trimmed = json?.Trim();\nif (string.IsNullOrEmpty(trimmed) || trimmed == \"null\")\n{\n    throw new ArgumentException(\"策略文件内容为空或为 null\");\n}\nvar strategy = JsonCombatStrategyParser.Parse(json);","typeGuard":null,"tryCatchPattern":"try\n{\n    var strategy = JsonCombatStrategyParser.Parse(json);\n}\ncatch (InvalidOperationException e) when (e.Message.Contains(\"反序列化失败\"))\n{\n    Logger.LogError(\"策略反序列化结果为空，请检查文件内容\");\n}","preventionTips":["Ensure the JSON root is an object (starts with '{'), not 'null', an array, or empty.","Check the file was fully written and not truncated or cleared.","If downloading strategy files, verify the download completed successfully."],"tags":["json-strategy","deserialization","null","validation"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}