【问题标题】:jsoncpp empty root node with commentjsoncpp 带注释的空根节点
【发布时间】:2014-07-31 16:23:38
【问题描述】:

使用 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);

我做的事情真的很愚蠢吗?有人有什么建议吗?

【问题讨论】:

    标签: jsoncpp root-node


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 2012-12-08
      • 2016-12-10
      相关资源
      最近更新 更多