Tencent/APIJSON · error · IllegalArgumentException
JSON 对象格式不正确 !正确示例例如 "User": {}
Error message
JSON 对象格式不正确 !正确示例例如 "User": {} What it means
batchVerify() in AbstractParser rejects a batch request whose top-level JSON object is null or empty. A batch request must contain at least one table object such as "User": {} so the parser has something to verify and execute.
Source
Thrown at APIJSONORM/src/main/java/apijson/orm/AbstractParser.java:2392
break;
}
}
if (hasTag == false) {
objAttrMap.put(KEY_TAG, isPost && isTableArray(objKey)
? objKey.substring(0, objKey.length() - 2) + ":[]" : objKey);
}
}
}
}
protected M batchVerify(RequestMethod method, String tag, int version, String name, @NotNull M request, int maxUpdateCount, SQLCreator<T, M, L> creator) throws Exception {
M correctRequest = JSON.createJSONObject();
List<String> removeTmpKeys = new ArrayList<>(); // 请求json里面的临时变量,不需要带入后面的业务中,比如 @post、@get等
Set<String> reqSet = request == null ? null : request.keySet();
if (reqSet == null || request.isEmpty()) {
throw new IllegalArgumentException("JSON 对象格式不正确 !正确示例例如 \"User\": {}");
}
// 先收集所有显式方法,避免同一请求中方法指令的字段顺序影响对象解析结果。
for (String key : reqSet) {
RequestMethod keyMethod = KEY_POST.equals(key) ? RequestMethod.POST : KEY_METHOD_ENUM_MAP.get(key);
if (keyMethod == null) {
continue;
}
removeTmpKeys.add(key);
try {
parseMethodDirective(key, keyMethod, request);
}
catch (Exception e) {
Log.e(TAG, "parse method directive failed", e);
throw e;
}
}View on GitHub (pinned to 5284052872)
Solutions
- Send at least one table object: {"User": {"id": 1}}
- Guard client-side: skip the API call when the payload object has zero keys
- Check network tab to confirm the body was not emptied by a serializer or interceptor
Example fix
// before
POST /delete {}
// after
POST /delete {"User": {"id": 1}} Defensive patterns
Strategy: validation
Validate before calling
if (!req || Object.keys(req).length === 0) { throw new Error('batch request must contain at least one table object, e.g. {"User": {}}'); } Type guard
const isNonEmptyObject = o => o != null && typeof o === 'object' && !Array.isArray(o) && Object.keys(o).length > 0;
Try / catch
try { await client.delete(req); } catch (e) { if (e.message.includes('JSON 对象格式不正确')) alert('请选择至少一条记录'); else throw e; } Prevention
- Disable the submit button when the selection is empty
- Default the payload to a minimal {Table:{}} shape in the builder
When it happens
Trigger: POSTing {} or an empty body to a batch endpoint (e.g. /delete or /crud with batch semantics) that routes into batchVerify; client-side serialization bug that drops all keys before sending.
Common situations: Frontend builds the request from an empty selection (user ticked no rows); a fetch wrapper defaults to {} when the payload variable is undefined; gateway/proxy strips the body.
Related errors
- JSON格式不合法!
- ${key}: value 中 value 类型错误,只能是 String 或 Map<String, Object>
- ${key}: { ${objKey}: value 中 value 类型错误,只能是 String 或 Map<Str
- 请在最外层传 tag !一般是 Table 名,例如 "tag": "User"
- {method} 请求,{name} 里面不允许 {rk}:[] 等未定义的 Table[]:[{}] 批量操作键值对!
AI-assisted analysis of Tencent/APIJSON@5284052872 (2026-08-14).
Data as JSON: /api/errors/0f688238d3a5f436.
Report an issue: GitHub.