| 47 | } |
| 48 | |
| 49 | void ResponseParser::loadJSONResponse(const QString &response) |
| 50 | { |
| 51 | QJsonParseError Err; |
| 52 | QVariantMap sc = QJsonDocument::fromJson(response.toUtf8(), &Err).toVariant().toMap(); |
| 53 | |
| 54 | errorTxt = "None"; |
| 55 | |
| 56 | if (Err.error != QJsonParseError::NoError) { |
| 57 | errorTxt = "Json syntax error"; |
| 58 | error = true; |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | if (!sc.value("status_code").isValid() || isError(sc.value("status_code").toInt())) { |
| 63 | error = true; |
| 64 | if (sc.value("error").isValid()) { |
| 65 | errorTxt = sc.value("error").toString(); |
| 66 | |
| 67 | } else { |
| 68 | errorTxt = "Unknown error"; |
| 69 | } |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | error = false; |
| 74 | if (sc.value("number_of_total_results").isValid()) { |
| 75 | numResults = sc.value("number_of_total_results").toInt(); // sc.property("number_of_total_results").toInt32(); |
| 76 | |
| 77 | } else { |
| 78 | qDebug() << sc.value("oops").toString(); |
| 79 | } |
| 80 | |
| 81 | auto limit = sc.value("limit").toInt(); |
| 82 | auto offset = sc.value("offset").toInt(); |
| 83 | auto total = sc.value("number_of_total_results").toInt(); |
| 84 | if (limit > 0) { |
| 85 | totalPages = (total / limit) + (total % limit > 0 ? 1 : 0); |
| 86 | currentPage = (offset / limit) + 1; |
| 87 | } else { |
| 88 | totalPages = currentPage = 1; |
| 89 | } |
| 90 | } |
no test coverage detected