Encoding and escaped strings
Unsolved
General and Desktop
-
Hello,
after sending a request to a remote service, QNetworkReply returns an encoded string, i.e.:QByteArray data = reply->readAll(); qDebug() << data;
"name":"citt\xC3\xA0"
I need to pass this string (it's a json) to QJsonDocument. Usually I do:
QJsonDocument doc = QJsonDocument::fromJson(data);
But now the output of the name field is:
citt?
I'm quite confused about encoding and escaping.
I tried the following:- convert the raw (escaped) data to UTF-8
- convert the QString to QByteArray to create the JSON doc
QByteArray raw = reply->readAll(); QJsonDocument doc = QJsonDocument::fromJson(QString::fromUtf8(raw).toUtf8()); qDebug() << doc.toJson();
anyway the output is still:
citt?
I'm expecting:
città
-
@Mark81
Curious. What about:qDebug() << (QString::fromUtf8(value) == QStringLiteral("citt\u00E0"));
Where
value
is the JSON value of that particular field (i.e.città
).PS.
What I'm trying to figure out is if this is an output issue, or encoding issue.