JSONCPP Writing to files

后端 未结 5 1898
我在风中等你
我在风中等你 2020-12-24 02:26

JSONCPP has a writer, but all it seems to do is get info from the parser and then output it into a string or a stream. How do I make it alter or create new objects, arrays,

5条回答
  •  醉梦人生
    2020-12-24 02:47

    AFAICT, you create objects of type Json::Value, which caters for all the JSON data-types, and pass the result to a Json::Writer (one of its derived types, to be specific), or simply to a stream.

    E.g.: to write an array of three integers to a file:

    Json::Value vec(Json::arrayValue);
    vec.append(Json::Value(1));
    vec.append(Json::Value(2));
    vec.append(Json::Value(3));
    std::cout << vec;
    

提交回复
热议问题