Json 值的类型是String
的,QJsonObject
需要先toString()
再toInt()
, 直接toInt值是0.
#include <QCoreApplication>
#include <QJsonObject>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QJsonObject obj;
obj["code"] = "123";
int toInt = obj["code"].toInt();
int toStringToInt = obj["code"].toString().toInt();
qDebug() << toInt;
qDebug() << toStringToInt;
return a.exec();
}