简体   繁体   中英

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\ße": "Ahornweg 5", "Name":"M�ller"}

Hope someone can help me. Every help is appreciated.

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM