[Interest] Support of russian language in QJson-classes

Dmitrii Volosnykh dmitrii.volosnykh at gmail.com
Mon Aug 19 14:29:40 CEST 2013


I am trying to write simple JSON-document:
{
    "тест": "тест"
}
and get the following result in file:
{
    "те\u0004\u0000": "тест"
}

If, for example, I add another letter it becomes:
{
    "тесто": "тесто"
}
is escaped as so:
{
    "тест\u0005": "тесто"
}

I've played with different string and it always behaves in the same
manner: the value is printed straightforwardly, but the key is escaped
for unknown reason. More over, escaped symbols are always at the end
of the string.

Here is example code I use:

#include <QtCore/QCoreApplication>
#include <QtCore/QtDebug>
#include <QtCore/QFile>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QJsonObject object;
    const QString& test = QString::fromUtf8("тесто");
    object[test] = test;
    QJsonDocument document(object);

    QFile file("test.json");
    bool ok = file.open(QFile::WriteOnly | QFile::Truncate);
    Q_ASSUME(ok);
    QByteArray bytes = document.toJson();
    const int writtenLength = file.write(bytes);
    Q_ASSUME(writtenLength == bytes.size());
    file.close();

    ok = file.open(QFile::ReadOnly);
    Q_ASSUME(ok);
    bytes = file.readAll();
    Q_ASSUME(bytes.size() == file.size());
    Q_ASSUME(bytes == document.toJson());

    return a.exec();
}



More information about the Interest mailing list