Closed
Description
Describe the bug
Platform: Win10 x64, VS2019, jsoncpp-master
Language: MFC
There some Chinese characters in the "setting.json" which is encoded using UTF-8. And my MFC project is using Unicode character set, When I use the CharReaderBuilder.parseFromStream() to read the "setting.json", all of the Chinese characters becomes garbled and all English characters are right.
So how should I read the Chinese json file correctly?
The code:
Json::CharReaderBuilder jsonBuilder;
Json::Value jsonRoot;
std::ifstream ifs;
ifs.open("D://Device.json", std::ios::binary);
jsonBuilder["collectComments"] = FALSE;
JSONCPP_STRING errs;
if (parseFromStream(jsonBuilder, ifs, &jsonRoot, &errs))
{
UINT len = 0;
len = jsonRoot.size();
}
for (UINT i = 0; i < jsonRoot.size(); i++)
{
CString tmp;
tmp = jsonRoot[i]["SoftwwareName"].asCString(); // tmp is garbled, not shows "测试用软件"
}
The setting.json:
[
{
"DeviceName":"设备名称",
"SoftwwareName":"测试用软件",
"IsUsed":"yes"
}
]
Any idea?
Metadata
Metadata
Assignees
Labels
No labels