1

我正在尝试使用 ArduinoJson 来解析 Google 的 quickdraw 数据集,其中包含 .ndjson 文件,其中包含多个对象。我想出了如何使用以下简单代码检索文件中的第一个对象:

DeserializationError deserialization_error = ArduinoJson::deserializeJson(doc, as_cstr);
if (deserialization_error) {
    printf("deserializeJson() failed: %s\n", deserialization_error.c_str());
}

但是,这只解析 ndjson 文件中的第一个对象。

根据网站,我觉得应该自动发生其他事情:

NDJSON, JSON Lines
When parsing a JSON document from an input stream, ArduinoJson stops reading as soon as the document ends (e.g., at the closing brace).

This feature allows to read JSON documents one after the other; for example, it allows to read line-delimited formats like NDJSON or JSON Lines.

{"event":"add_to_cart"}
{"event":"purchase"}

有什么方法可以获取解析对象的字节长度,我可以继续使用 cstring 来解析连续的对象吗?我确实打印出了 cstring,它确实包含整个 ndjson 文件。

4

1 回答 1

0

我找到了。

只需多次调用:

  DeserializationError error = deserializeJson(doc, sceneFile);

或者:

  deserializeJson(docline1, sceneFile);

  deserializeJson(docline2, sceneFile);

  deserializeJson(docline3, sceneFile);
于 2020-07-12T20:26:29.880 回答