简体   繁体   English

Jsoncpp 库中的 UTF-8

[英]UTF-8 in Jsoncpp Lib

I have a problem while using the jsoncpp lib in a project.在项目中使用 jsoncpp 库时遇到问题。 I tried to read, edit and write a local json files.我尝试读取、编辑和写入本地 json 文件。 The problem i have, is that i can't find a way to get the encoding of writing/reading to UTF-8.我遇到的问题是,我找不到将写入/读取编码转换为 UTF-8 的方法。 It always uses ASCII.它总是使用 ASCII。 This is an Example Json File:这是一个示例 Json 文件:

{"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:如果我像这样使用它,jsonfile 将如下所示:

{ "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.对于将来想知道的人,阅读这个问题,我花了一些时间,因为我是编码初学者,但这与您在 IDE 中使用的编码有关。 Make sure that it's really UTF-8!确保它真的是 UTF-8!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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