• Forum has been upgraded, all links, images, etc are as they were. Please see Official Announcements for more information

How to parse the cryptsy json api with Qt5/C++?

vertoe

Three of Nine
This might be a bit off topic, but as I'm writing a mobile app to display darkcoin prices I'm currently stuck to read the (awful!) cryptsy json api. Did anyone try that before?
This: http://pubapi.cryptsy.com/api.php?method=singleorderdata&marketid=155
Code:
double Cryptsy::doStuff(QNetworkReply* reply)
{
    double pair = -1.0f;
    if (reply->error() != QNetworkReply::NoError)
    {
        pair = 0.0f;
    }
    else
    {
        QString data = QString(reply->readAll()); // <--- contains the whole JSON as string
        QJsonDocument jsonResponse = QJsonDocument::fromJson(data.toUtf8());
        QJsonObject jsonObject = jsonResponse.object();
        qDebug() << jsonObject["success"]; // <--- is always empty ""
        if (jsonObject["success"] == 1)
        {
            // do stuff ...
        }
    }
    return pair;
}
Any idea? Exactly the same code works for the mintpal api (jsonObject["status"] == "success") and I don't really see where the difference is...
That: https://api.mintpal.com/v2/market/stats/DRK/BTC
 
I'm taking a shot in the dark here, but success in mintpal is a string, and success in cryptsy is an int, and QJsonObject operator[] returns a QJsonValue, so a direct comparison or using of QJsonValue against/with an int might not work how you expect it without extracting it from the QJsonValue container. Have you tried extracting it first?
Code:
QJsonObject jsonObject = jsonResponse.object();
int success = jsonObject["success"].toInt();
qDebug() << success;
if (success == 1)
{
// do stuff ...
}
 
try ... if (jsonObject["status"] == "success")
Oh sorry. Looking through the wrong link. scratch that. I have written a consumer for the cryptsy api and don't think it was anything odd, i would dump data, jsonResponse, and/or jsonObject to logs to get my eyes on what it thought came out and went in.
 
Last edited by a moderator:
Hi thanks,
I already did that,
  • QString data contains the complete JSON as string type
  • QJsonDocument jsonResponse contains the complete JSON as json document type
  • QJsonObject jsonObject anyways seems to be empty as I can not access "success" - and I have no idea how to dump the object to logs.
--toe
 
Back
Top