Efog
Efog

Reputation: 1179

toString(): numbers in JSON

I have QJsonObject, here is it:

QJsonObject({"key":"1475bee449df002422340510c355a7f8b48ea647","pts":960894,"server":"imv4.vk.com/im1976","ts":1626706149})

object["key"].toString() - ok, it returns 1475bee449df002422340510c355a7f8b48ea647
object["server"].toString() - ok, it returns imv4.vk.com/im1976
object["ts"].toString() - fail, returns "".
object["pts"].toString() - fail, returns "".


Yes, i can do QString::number(object["ts"].toInt());, but it isn't solution: value can be greater then MAXINT. Type of object["ts"] is double:

QJsonValue(double, 1626706149)

But object["ts"].toDouble() returns 1.62671e+09. Any suggestions?

Upvotes: 0

Views: 1470

Answers (1)

Alexander V
Alexander V

Reputation: 8698

It is explained there is a double value in QJsonValue object. A quick try confirms it won't convert to string for some reason, though it converts to 64 bit int with the casting.

QJsonValue jv((double)9999960902);
qDebug() << jv.toString();
qDebug() << jv.toInt();
qDebug() << (qint64)jv.toDouble();

And the output is:

""
0
9999960902

Upvotes: 1

Related Questions