I need to update the index (in JSON format) when writing a new file to disk, and since the files are classified, I use an object with this structure:
{ "type_1" : [ "file_1", "file_2" ], "type_2" : [ "file_3", "file_4" ] }
I thought this was an easy task for jsoncpp, but I probably missed something.
My code (simplified) is here:
std::ifstream idx_i(_index.c_str()); Json::Value root; Json::Value elements; if (!idx_i.good()) {
So, I open the file, reading the JSON data, if I cannot find it, I create a new array, the problem is that when I try to add a value to the array, it does not work, the array remains empty and is written to the file.
{ "type_1" : [], "type_2" : [] }
Tried to debug my code and jsoncpp calls, and everything looks fine, but the array is always empty.
source share