1

In the latest version of Ubuntu, code by qt creator. Qt version is qt 5.41. When I use QJsonDocument :: fromJson create json objects, json object is created successfully. Code is as follows:

#include <QJsonDocument>
#include <QDebug>

int main(int argc,char **argv){
    QString str = "{\"chinese\":\"china 中国\"}";
    QJsonDocument json;
    QJsonParseError error;
    json = QJsonDocument::fromJson(str.toUtf8(),&error);

    qDebug()<<json.toJson();
    //In Rhel5 Result:NULL

    qDebug()<<error.errorString();
     //In Rhel5 Result:invalid UTF8 string"

    str = "{\"english\":\"china english\"}";
    json = QJsonDocument::fromJson(str.toUtf8(),&error);

    qDebug()<<json.toJson();
   //In Rhel5 Result successful : 
  //    {
  //    "english": "china english"
  //     }

   qDebug()<<error.errorString();//In Rhel5 Result:no error occurred""
 return 0;
}

However, when the exact same code to run on rhel5, I got a description of the error: invalid UTF8 string. On rhel5, compiled qt5 library functions, so you can execute programs on qt5 rhel5.

When json string is in English, rhel5 run properly, correct json string.

In addition, rhel5 support utf-8 encoded.

Ilya
  • 5,377
  • 2
  • 18
  • 33
alfred
  • 11
  • 2
  • Try to output somewhere your str before parsing. Some compilers doesn't support sources in utf8. – Dmitry Sazonov Feb 28 '16 at 09:10
  • it is not work.i can use qDebug().Chinese can be output。@SaZ – alfred Feb 28 '16 at 09:28
  • `qDebug` is not good solution, because console may not support unicode. Try to do an output to file. Be sure, that ICU is used as string backend by Qt in your target platform. – Dmitry Sazonov Feb 28 '16 at 09:31
  • SaZ, that is my test code: int main(int argc,char **argv){ QByteArray str = "{\"chinese\":\"广东\"}"; qDebug()< – alfred Feb 28 '16 at 10:00
  • In rhel 5,i can get the result.txt. It can display Chinese. I use notepad ++ View result.txt. it is encode in UTF-8 without BOM .@SaZ,it is right? – alfred Feb 28 '16 at 10:01

0 Answers0