{"record":{"id":"b281a0d197bc5e08","repo":"Tencent/APIJSON","slug":"json","errorCode":null,"errorMessage":"JSON格式不合法！{}! {}","messagePattern":"JSON格式不合法！(.+?)! (.+?)","errorType":"validation","errorClass":"UnsupportedEncodingException","httpStatus":null,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractParser.java","lineNumber":452,"sourceCode":"\t\tif (verifier == null) {\n\t\t\tverifier = createVerifier().setVisitor(getVisitor());\n\t\t}\n\t\tverifier.setParser(this);\n\t\treturn verifier;\n\t}\n\n\t/**解析请求JSONObject\n\t * @param request => URLDecoder.decode(request, UTF_8);\n\t * @return\n\t * @throws Exception\n\t */\n\tpublic static <M extends Map<String, Object>> M parseRequest(String request) throws Exception {\n\t\ttry {\n\t\t\tM req = JSON.parseObject(request);\n\t\t\tObjects.requireNonNull(req);\n\t\t\treturn req;\n\t\t} catch (Throwable e) {\n\t\t\tthrow new UnsupportedEncodingException(\"JSON格式不合法！\" + e.getMessage() + \"! \" + request);\n\t\t}\n\t}\n\n\t/**解析请求json并获取对应结果\n\t * @param request\n\t * @return\n\t */\n\t@Override\n\tpublic String parse(String request) {\n\t\treturn JSON.toJSONString(parseResponse(request));\n\t}\n\t/**解析请求json并获取对应结果\n\t * @param request\n\t * @return\n\t */\n\t@NotNull\n\t@Override\n\tpublic String parse(M request) {","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java#L434-L470","documentation":"parseRequest(String) wraps JSON.parseObject plus a null check; any parse failure or null result is rethrown as UnsupportedEncodingException with message 'JSON格式不合法！<cause>! <original request>'. It is the entry gate: the raw request body must be a valid JSON object string before any APIJSON parsing begins.","triggerScenarios":"Sending a malformed body: truncated JSON, single quotes, trailing commas, a JSON array instead of object, form-encoded or XML content, or an empty body. Also double-URL-encoding that corrupts the payload before decode.","commonSituations":"HTTP client sends the JSON with wrong Content-Type handling or manual string concatenation; proxy/gateway mangles the body; client library serializes undefined to invalid tokens; version change switched from form params to raw body without updating the client.","solutions":["Print the request string included in the message and run it through any JSON validator to find the syntax error","Use a real JSON serializer client-side instead of string concatenation/template literals","Ensure the endpoint receives a raw JSON object body ({} outermost), not an array or query-string","Check for encoding damage: URL-decode twice only if your transport requires it"],"exampleFix":"// before\nString body = \"{'name': 'a',}\");\n// after\nString body = \"{\\\"name\\\": \\\"a\\\"}\";","handlingStrategy":"validation","validationCode":"Object parsed = new JSONParser().parse(body);\nif (!(parsed instanceof JSONObject)) throw new IOException(\"body is not a JSON object\");","typeGuard":"boolean isValidJsonObjectString(String s) {\n  try { return s != null && s.trim().startsWith(\"{\") && new JSONParser().parse(s) instanceof JSONObject; }\n  catch (Exception e) { return false; }\n}","tryCatchPattern":"catch (UnsupportedEncodingException e) { if (e.getMessage().contains(\"JSON格式不合法\")) { logPayload(body); return clientError(\"invalid json body\"); } throw e; }","preventionTips":["Always use a JSON serializer; never template-concatenate bodies","Validate the body with a JSON schema/linter in tests","Log the offending payload (message includes it) once to find the exact syntax break"],"tags":["apijson","json","parse","invalid-input"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}