Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QJson parsing without quotation marks



  • Example QByteArray (ba) looks like:

    {
    "testA": "1234",
    "testB": 5678,
    }

    Parsing code:

    QJsonDocument jsonResponse = QJsonDocument::fromJson(ba);
    QJsonObject tokenObj = jsonResponse.object();
    testA= tokenObj["testA"].toString();
    testB = tokenObj["testB"].toString();

    testA properly returns "1234" while testB returns ""

    Any ideas are welcome, thanks in advance!



  • Hi,

    testB = tokenObj["testB"].toInt();
    

    will work as you provided a number 5678.


Log in to reply