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);
私は本当に愚かなことをしていますか?誰にもヒントはありますか?