{"record":{"id":"864f95db294aec52","repo":"babalae/better-genshin-impact","slug":"json-864f95","errorCode":null,"errorMessage":"翻译文件不是有效的 JSON 字典。","messagePattern":"翻译文件不是有效的 JSON 字典。","errorType":"exception","errorClass":"JsonException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/ViewModel/Pages/CommonSettingsPageViewModel.cs","lineNumber":150,"sourceCode":"        {\n            try\n            {\n                using var request = new HttpRequestMessage(HttpMethod.Get, url);\n                request.Headers.UserAgent.ParseAdd(\"BetterGenshinImpact\");\n                using var response = await httpClient.SendAsync(request);\n                if (response.StatusCode == HttpStatusCode.NotFound)\n                {\n                    lastError = new HttpRequestException(\"Language file not found.\", null, response.StatusCode);\n                    continue;\n                }\n\n                allNotFound = false;\n                response.EnsureSuccessStatusCode();\n                bytes = await response.Content.ReadAsByteArrayAsync();\n\n                var json = Encoding.UTF8.GetString(bytes);\n                _ = JsonConvert.DeserializeObject<Dictionary<string, string>>(json)\n                    ?? throw new JsonException(\"翻译文件不是有效的 JSON 字典。\");\n                break;\n            }\n            catch (Exception e)\n            {\n                lastError = e;\n                allNotFound = false;\n            }\n        }\n\n        if (bytes == null)\n        {\n            if (allNotFound)\n            {\n                await ThemedMessageBox.WarningAsync($\"语言文件不存在：{cultureName}.json\");\n                return;\n            }\n\n            throw new Exception($\"下载语言文件失败：{cultureName}.json\", lastError);","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/ViewModel/Pages/CommonSettingsPageViewModel.cs#L132-L168","documentation":"JsonConvert.DeserializeObject<Dictionary<string,string>> returns null when the downloaded JSON is the literal \"null\" or content that deserializes to a null reference (not an object map). The null-coalescing throw converts that into a JsonException so a corrupt/empty file is never written to disk. Note: malformed JSON throws JsonException earlier and is swallowed by the outer catch, so this specific line only fires on JSON that is valid but null/non-object.","triggerScenarios":"A 200 response whose body is the JSON literal \"null\", an empty/whitespace body where DeserializeObject returns null, or a valid JSON scalar/array that the Dictionary binding resolves to null.","commonSituations":"Upstream repository file temporarily empty during a deploy; a mirror serving a placeholder; a CDN error page that is valid JSON but not a string->string object; content-type mismatch serving non-dict JSON.","solutions":["Inspect the downloaded bytes before deserializing — reject empty/whitespace content early.","Validate the result is a non-null, non-empty Dictionary before accepting it.","Check the upstream bettergi-i18n repository for the given culture — the file may be empty or a stub."],"exampleFix":"// before\n_ = JsonConvert.DeserializeObject<Dictionary<string, string>>(json)\n    ?? throw new JsonException(\"翻译文件不是有效的 JSON 字典。\");\n\n// after\nif (string.IsNullOrWhiteSpace(json))\n    throw new JsonException(\"翻译文件为空。\");\nvar dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);\nif (dict is null || dict.Count == 0)\n    throw new JsonException(\"翻译文件不是有效的 JSON 字典。\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(json))\n    throw new JsonException(\"翻译文件为空。\");\nvar dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);\nif (dict is null || dict.Count == 0)\n    throw new JsonException(\"翻译文件不是有效的 JSON 字典。\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var dict = JsonConvert.DeserializeObject<Dictionary<string,string>>(json);\n    if (dict is null || dict.Count == 0)\n        throw new JsonException(\"翻译文件不是有效的 JSON 字典。\");\n}\ncatch (JsonException)\n{\n    // skip this mirror, try the next URL\n    continue;\n}","preventionTips":["Reject empty/whitespace response bodies before deserializing.","Validate the dictionary is non-null and non-empty before writing it to disk.","Treat a non-dict JSON payload the same as a download failure and try the next mirror."],"tags":["json","i18n","network"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}