在 vert.x 中处理大 json 字符串的正确方法是什么?
What is the correct way to handle large json strings in vert.x?
我有一个来自 HTTP API 的大型(目前大小为 2MB,可能会增长到 10MB)JSON 对象(包含对象数组)API 我需要使用:
client.get(...)
.send(ar -> {
JsonObject jsonObject = new JsonObject(ar.result().bodyAsBuffer());
});
这会导致错误:
Jan 09, 2020 2:11:14 PM io.vertx.core.impl.ContextImpl
SEVERE: Unhandled exception
io.vertx.core.json.DecodeException: Failed to decode:Unexpected character (',' (code 44)): expected a value
at [Source: (io.netty.buffer.ByteBufInputStream); line: 70674, column: 27]
at io.vertx.core.json.Json.decodeValue(Json.java:222)
at io.vertx.core.json.JsonObject.fromBuffer(JsonObject.java:975)
at io.vertx.core.json.JsonObject.<init>(JsonObject.java:85)
我认为出现此错误是因为 JSON 字符串太大,而 Json 字符串似乎是有效的。 vert.x 有没有办法处理大的 Json Strings/files?还是这里发生了其他事情?
10 MB json 文件在移动设备上可能很大。
您应该在代码中使用 JsonArray
而不是 JsonObject
:
JsonArray jsonArray = new JsonArray(ar.result().bodyAsBuffer())
JSON 无效,但用于手动验证 JSON 的工具没有捕捉到这一点。
错误出在第三方 api,当双字段为空时,它会将键的值留空而不是空值。
这个:
{
"String": "string",
"Double": ,
"AnotherDouble": 0.1
}
应该是这样的:
{
"String": "string",
"Double": null,
"AnotherDouble": 0.1
}
修复是向开发人员报告无效 JSON,他们修补了使空白值变为 null 而不是空白的问题。
我有一个来自 HTTP API 的大型(目前大小为 2MB,可能会增长到 10MB)JSON 对象(包含对象数组)API 我需要使用:
client.get(...)
.send(ar -> {
JsonObject jsonObject = new JsonObject(ar.result().bodyAsBuffer());
});
这会导致错误:
Jan 09, 2020 2:11:14 PM io.vertx.core.impl.ContextImpl
SEVERE: Unhandled exception
io.vertx.core.json.DecodeException: Failed to decode:Unexpected character (',' (code 44)): expected a value
at [Source: (io.netty.buffer.ByteBufInputStream); line: 70674, column: 27]
at io.vertx.core.json.Json.decodeValue(Json.java:222)
at io.vertx.core.json.JsonObject.fromBuffer(JsonObject.java:975)
at io.vertx.core.json.JsonObject.<init>(JsonObject.java:85)
我认为出现此错误是因为 JSON 字符串太大,而 Json 字符串似乎是有效的。 vert.x 有没有办法处理大的 Json Strings/files?还是这里发生了其他事情?
10 MB json 文件在移动设备上可能很大。
您应该在代码中使用 JsonArray
而不是 JsonObject
:
JsonArray jsonArray = new JsonArray(ar.result().bodyAsBuffer())
JSON 无效,但用于手动验证 JSON 的工具没有捕捉到这一点。
错误出在第三方 api,当双字段为空时,它会将键的值留空而不是空值。
这个:
{
"String": "string",
"Double": ,
"AnotherDouble": 0.1
}
应该是这样的:
{
"String": "string",
"Double": null,
"AnotherDouble": 0.1
}
修复是向开发人员报告无效 JSON,他们修补了使空白值变为 null 而不是空白的问题。