8

Let suppose I have this Json file:

[
    {
        "id": 0
    }
]

using jsoncpp, i can have a Json::Value object by doing this:

Json::Value node = root[0u]["id"];

OK, somewhere else in the code, I'm getting that node object, and I want to get some info out of it. I can get its value, like this:

int node_value = node.asInt();

But how can I get its NAME? (i.e the "id"). It should be something like:

string node_name  = node.Name(); //or maybe:
string node_name2 = node.Key(); 

but I can't find anything similar. Help? How can I get a node's name?

4

2 回答 2

10

您可以使用 Json::Value::getMemberNames() 来遍历名称。

Json::Value value;
for (auto const& id : value.getMemberNames()) {
    std::cout << id << std::endl;
}
于 2013-12-10T14:40:56.783 回答
1

你需要一个向上指针吗?这不是一个坏主意,但是为上指针添加一个字段会破坏二进制兼容性(这非常重要)。所以是的,你需要包装它。

目前,子值只是 a Value,就像其他任何东西一样。

于 2015-02-16T17:51:50.277 回答