I have problem with QJsonObject
character encoding. QJsonObject::toJson()
returns string with international characters as hex values:
s: "żółć"
obj: QJsonObject({"s":"żółć"})
doc: QJsonDocument({"s":"żółć"})
JSON: "{\n \"s\": \"\xC5\xBC\xC3\xB3\xC5\x82\xC4\x87\"\n}\n"
Code:
#include <QCoreApplication>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString s = "żółć";
qDebug() << "s: " << s;
QJsonObject obj;
obj["s"] = s;
qDebug() << "obj: " << obj;
QJsonDocument doc(obj);
qDebug() << "doc: " << doc;
qDebug() << "JSON: " << doc.toJson();
return a.exec();
}
How can I get JSON string with international characters?