mirror of
https://github.com/YACReader/yacreader
synced 2025-07-26 17:04:45 -04:00
added new comic_vine folder containing all the ComicVine related clases
added QtScript dependency (json parser)
This commit is contained in:
42
YACReaderLibrary/comic_vine/model/response_parser.cpp
Normal file
42
YACReaderLibrary/comic_vine/model/response_parser.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "response_parser.h"
|
||||
|
||||
#include <QtScript>
|
||||
#include <QDebug>
|
||||
|
||||
ResponseParser::ResponseParser(QObject *parent) :
|
||||
QObject(parent),error(false),numResults(-1)
|
||||
{
|
||||
}
|
||||
|
||||
bool ResponseParser::responseError()
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
qint32 ResponseParser::getNumResults()
|
||||
{
|
||||
return numResults;
|
||||
}
|
||||
|
||||
void ResponseParser::loadJSONResponse(const QString &response)
|
||||
{
|
||||
QScriptEngine engine;
|
||||
QScriptValue sc;
|
||||
sc = engine.evaluate("(" + response + ")");
|
||||
|
||||
if (!sc.property("error").isValid() && sc.property("error").toString() != "OK")
|
||||
{
|
||||
error = true;
|
||||
numResults = -2;
|
||||
qDebug("Error detected");
|
||||
}
|
||||
else
|
||||
{
|
||||
error = false;
|
||||
if(sc.property("number_of_total_results").isValid())
|
||||
numResults = sc.property("number_of_total_results").toString().toInt();// sc.property("number_of_total_results").toInt32();
|
||||
else
|
||||
numResults = -3;
|
||||
qDebug() << sc.property("number_of_total_results").toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user