首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用ArduinoJson从同一文件中检索多个NDJSON对象?

如何使用ArduinoJson从同一文件中检索多个NDJSON对象?
EN

Stack Overflow用户
提问于 2020-05-30 03:31:02
回答 1查看 61关注 0票数 1

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

代码语言:javascript
复制
DeserializationError deserialization_error = ArduinoJson::deserializeJson(doc, as_cstr);
if (deserialization_error) {
    printf("deserializeJson() failed: %s\n", deserialization_error.c_str());
}

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

根据website的说法,我感觉其他事情应该会自动发生:

代码语言:javascript
复制
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文件。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-13 04:26:30

我找到了。

只需多次调用:

代码语言:javascript
复制
  DeserializationError error = deserializeJson(doc, sceneFile);

或者:

代码语言:javascript
复制
  deserializeJson(docline1, sceneFile);

  deserializeJson(docline2, sceneFile);

  deserializeJson(docline3, sceneFile);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62093402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档