0

I am trying to use integer values from a list in a JSON file, but I seem to be having trouble with parsing the file.

I tried changing the line "Reader reader;" to "CharReader reader;", but that doesn't work with the parse function.

#include <fstream>
#include "json\json.h"
using namespace std;
using namespace Json;

int main()
{
    ifstream f("settings.json");
    Reader reader; // line 11
    Value settings;
    f >> settings;
    reader.parse(f, settings); // line 14
    Value rxv = settings["res"][0u];
    Value ryv = settings["res"][1u];
    int screenres_x = rxv.asInt();
    int screenres_y = ryv.asInt();

Content of JSON:

{
    "res": [1024, 768],
    "windowed": true,
    "fpscap": true
}

I expect the settings value to contain the contents of the JSON file, but I am getting the following errors:

"'Json::Reader': Use CharReader and CharReaderBuilder instead." on line 11

"'Json::Reader::__autoclassinit2': Use CharReader and CharReaderBuilder instead." on line 11

"'Json::Reader::Reader': Use CharReader and CharReaderBuilder instead." on line 11

"'Json::Reader::parse': Use CharReader and CharReaderBuilder instead." on line 14
Ham Sandwich
  • 11
  • 1
  • 1
  • You can't just swap the type names then give up when it doesn't work. You have to actually look up the suggested replacement feature and read about how to use it, in the documentation... – Lightness Races in Orbit Oct 15 '19 at 19:49

1 Answers1

4

Visual Studio throws the error C4996, which means that the use of Json::Reader is apparently deprecated.

You can just use the overloaded >> operator, though:

#include <fstream>
#include "json\json.h"
using namespace std;
using namespace Json;

int main()
{
    ifstream f("settings.json");
    Value settings;
    f >> settings;
    // Do something with settings
}
Simon
  • 405
  • 2
  • 8