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.