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, values, strings, et cetera and write them into the file?
Here's the code: #include <json/value. h> #include <fstream> std::ifstream people_file("people. json", std::ifstream::binary); people_file >> people; cout<<people; //This will print the entire json object. //The following lines will let you access the indexed objects.
#include<json/writer.h>
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" } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With