0

使用 jsoncpp,如果我使用以下代码,我会得到一个带有注释的根节点和 nullValue 的 Json::ValueType:

std::string somejson("// Configuration options\
{\
// Default encoding for text\
\"encoding\" : \"UTF-8\",\
\
// Plug-ins loaded at start-up\
\"plug-ins\" : [\
    \"python\",\
    \"c++\",\
    \"ruby\"\
    ],\
    \
// Tab indent size\
\"indent\" : { \"length\" : 3, \"use_space\": true }\
}");
Json::Value root;
Json::Reader reader;
reader.parse(somejson, root);

但是,如果我自己创建一个空的根节点并添加注释,它就会爆炸:

Json::Value rootNode = Json::Value(Json::nullValue);
rootNode.setComment("My wonderful comment", Json::commentBefore);

我做的事情真的很愚蠢吗?有没有人有任何提示?

4

1 回答 1

1

很明显。一个简单的跟踪显示 Value::CommentInfo::setComment 断言评论必须以 / 开头

我的评论没有。需要更多的咖啡。

于 2014-08-01T09:54:29.670 回答