c++jsonjsoncpp

UTF-8 in Jsoncpp Lib


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.


Solution

  • 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!