Tencent / rapidjson

A fast JSON parser/generator for C++ with both SAX/DOM style API
http://rapidjson.org/
Other
14.26k stars 3.53k forks source link

Is there any way to get node by path? #1206

Open damianpuci opened 6 years ago

damianpuci commented 6 years ago

My json structure looks like this:

{
    "main_node": {
        "child_node1": "xxx",
        "child_node2": {
            "name": "yyy",
            "path": "zzzz"
        },
        "child_node3": {
            "name": "aaaaa",
            "version": "1.0",
        }
    }
}

I have recursive function to search node by name so I can create string with path to this node. Let suppose that we want to get node "version". This is how string with path will look like: "/main_node/child_node3/version". I don't want to get value of this node("1.0") which I can get by calling rapidjson::GetValueByPointer(this->jsonDocument, rapidjson::Pointer(path2Parent)); Is there any way to get whole node as a pointer to rapidjson::Value type?

miloyip commented 6 years ago

It does return the pointer to rapidjson::Value:

template <typename T>
typename T::ValueType* GetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, size_t* unresolvedTokenIndex = 0);
damianpuci commented 6 years ago

So I will get "1.0", yes?

miloyip commented 6 years ago

Your question is quite confusing to me... It returns a point to Value and you need to call Value::GetDouble() to get the numerical value 1.0.

prantarn commented 3 years ago

Hi, @damianpuci . I am currently stuck at a place where I need to retrieve the path to a given node. Can you please share the code?