【发布时间】:2016-10-07 14:09:01
【问题描述】:
QJsonObject 字符编码有问题。 QJsonObject::toJson() 以十六进制值返回带有国际字符的字符串:
s: "żółć"
obj: QJsonObject({"s":"żółć"})
doc: QJsonDocument({"s":"żółć"})
JSON: "{\n \"s\": \"\xC5\xBC\xC3\xB3\xC5\x82\xC4\x87\"\n}\n"
代码:
#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();
}
如何获取带有国际字符的 JSON 字符串?
【问题讨论】:
-
没有。也就是 Qt Creator 调试输出控制台中的 qDebug():stackoverflow.com/questions/16884570/… JSON 与 UNICODE 定义良好。
标签: json qt character-encoding