我正在尝试编写一个从 Web API 获取一些 JSON 的 C++ Qt 4.7 应用程序。我做了一些阅读,JsonCpp 似乎是最好的。所以我建立它只是找到并将它添加到我的项目中就好了。
void RetrievingInformationPage::replyFinished(QNetworkReply *reply)
{
Json::Value root;
Json::Reader reader;
bool success = reader.parse(reply->readAll().data(), root);
// here be issues
qDebug() << QString::fromStdString(root["data"][30]["name"].toStyledString());
return;
}
当我运行此代码时,它会输出我正在测试的名称(它是一个带有 unicode 的名称),但特殊字符输出为完全乱码(“à¤?à¥à¤²à¤¿à¤«à¤°à ¥à¤¡")。unicode 以 JSON 字符串“\u0915\u094d\u0932\u093f\u092b\u0930\u094d\u0921”的形式输入,然后我假设 JsonCpp 将其转换为实际的 unicode 字符。我希望 QString::fromStdString 将 unicode 放入 std::string 并将其存储在 QString 中,但显然它在某个地方搞砸了。
我错过了什么?