我正在使用 RapidJSON 在 C++ 中处理一个 2MB 的 JSON 字符串。我知道您可以通过以下方式尝试从当前级别获取对象:
rapidjson::Value& json = document["object1"];
但是,有没有一种方法可以一次获得多个层次的东西,而不必一路获得每个(并且可能与我的最终目标无关)中间对象?一些概念上的东西:
rapidjson::Value& member = document["object1.object2.object3.member"];
我搜索过这个但没有找到任何答案,所以我相信答案是否定的,但我想确定一下。
最佳答案
使用 RapidJSON 的 JSON pointer API :
#include "rapidjson/pointer.h"
Document document;
if (Value* member = GetValueByPointer(document, "/object1/object2/object3/member")) {
// the pointer was sucessfully resolved in the document
// do something with member
}
关于c++ - 获取嵌套的 JSON 成员而不直接获取每个中间对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55579486/