Hey all, quick question:
I'm using jsoncpp to try to load from a json file, and despite trying to read the documentation (I'm still rather new, and sometimes documentation can go over my head), I'm a little confused still on some details.
I've gotten a bare bones test working:
std::string json_example = "{\"array\":\
[\"item1\",\
\"item2\"], \
\"not an array\": \
\"asdf\" \
}";
Json::Value root;
Json::Reader reader;
bool parsedSuccess = reader.parse(json_example, root, false);
if(not parsedSuccess)
{
std::cout<<"whoops"<<std::endl;
}
const Json::Value array = root["array"];
for(unsigned int index = 0; index<array.size(); ++index)
{
std::cout<<"Element "<<index<<" in array: "<<array[index].asString()<<std::endl;
}
This seems to work. However, it's only reading from a string created in the code. Is there supposed to be a way to load directly from a file in the directory? I was about to try to just load a string from a file using fstream and then parse it, but I thought there's perhaps a cleaner way (hopefully within the jsoncpp code) to do this.
Anyhow, any recommendations here would be greatly appreciated. This is my first foray into reading/writing to files (I've been procrastinating learning it). I'm mostly wanting to read/write things like game options, character data, save states etc for the game. Feel free to let me know if I'm going about this the wrong way, or point me to a decent tutorial. There seems to be a lot of options out there, but little in the way of clear tutorials. I toyed with XML for a little bit before settling on json. But, I'm not rigidly set on it.
Thanks in advance for any input.
Cheers :)