Using JsonCpp and Qt Together (Unicode issues)

I am trying to write a C ++ Qt 4.7 application that gets some JSON from a web API. I did some reading and JsonCpp seems to be the best. So I built it, just found and added it to my project.

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;
}

When I run this code, it prints out the name I'm testing (this is the name with unicode in it), but special characters are output as complete gibberish ("à¤? ¥ लà¤àà" "¤ ° à ¥ ड "). Unicode was included as a JSON string "\ u0915 \ u094d \ u0932 \ u093f \ u092b \ u0930 \ u094d \ u0921", then I assume JsonCpp will convert it to actual Unicode characters. I was hoping that QString :: fromStdString would take unicode in std :: string and store it in QString, but obviously it gets confused somewhere.

What am I missing?

+3
1

JsonCpp, UTF-8. QStrings QString:: fromUTF8 qDebug qPrintable

QString:: fromStdString QString:: fromAscii, .

+2

Source: https://habr.com/ru/post/1775116/


All Articles