1

I have a problem while using the jsoncpp lib in a project. I tried to read, edit and write a local json files. The problem i have, is that i can't find a way to get the encoding of writing/reading to UTF-8. It always uses ASCII. This is an Example Json File:

{"Name": "Müller"}

I'm using it like this:

std::ifstream ifs;
std::ofstream ofs;
Json::CharReaderBuilder builder;
Json::StreamWriterBuilder wbuilder;
const std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
Json::String errs;

parseFromStream(builder, ifs, &root, &errs);

string name = root["Name"].asString();
//if i try to use this data in my wxWidgets Gui now, the Output would be sth like M�ller

root["Straße"] = "Ahornweg 5";

writer->write(root, &ofs);

If i use it like this the jsonfile would look like this:

{ "Stra\u00dfe": "Ahornweg 5", "Name":"M�ller"}

Hope someone can help me. Every help is appreciated.

xPazone
  • 33
  • 2
  • `Stra\u00dfe` is exactly that `can help me` with what? – KamilCuk Sep 14 '20 at 18:37
  • Yes its the same value. but encoded differently. What I want in my Jsonfile is Straße and not Stra\u00fde. Because I cant acces it again with using root["Straße"]. I need to open it with root["Stra\u00dfe] and this is not working for this exact project – xPazone Sep 14 '20 at 18:43
  • You may need to use a different library. I didn't see anything in the jsoncpp docs about encodings there. I read docs for rapidjson which has info about encodings but even then I can't tell if it meets your requirements. – Hitobat Sep 14 '20 at 20:59

1 Answers1

0

For anyone in the future wondering, reading this question, it took me some time since I'm a beginner in coding, but it has something to do with the encoding you use in your IDE. Make sure that it's really UTF-8!

xPazone
  • 33
  • 2