JSONCPP Writing to files

后端 未结 5 1940
我在风中等你
我在风中等你 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:46

    #include
    

    Code:

        Json::Value event;   
        Json::Value vec(Json::arrayValue);
        vec.append(Json::Value(1));
        vec.append(Json::Value(2));
        vec.append(Json::Value(3));
    
        event["competitors"]["home"]["name"] = "Liverpool";
        event["competitors"]["away"]["code"] = 89223;
        event["competitors"]["away"]["name"] = "Aston Villa";
        event["competitors"]["away"]["code"]=vec;
    
        std::cout << event << std::endl;
    

    Output:

    {
            "competitors" : 
            {
                    "away" : 
                    {
                            "code" : [ 1, 2, 3 ],
                            "name" : "Aston Villa"
                    },
                    "home" : 
                    {
                            "name" : "Liverpool"
                    }
            }
    }
    

提交回复
热议问题