2018-07-07 13:08:57 +02:00
|
|
|
#include "common/NetworkResult.hpp"
|
|
|
|
|
|
|
|
#include "debug/Log.hpp"
|
|
|
|
|
|
|
|
#include <rapidjson/document.h>
|
|
|
|
#include <rapidjson/error/en.h>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
NetworkResult::NetworkResult(const QByteArray &data)
|
|
|
|
: data_(data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QJsonObject NetworkResult::parseJson() const
|
|
|
|
{
|
|
|
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(this->data_));
|
|
|
|
if (jsonDoc.isNull()) {
|
|
|
|
return QJsonObject{};
|
|
|
|
}
|
|
|
|
|
|
|
|
return jsonDoc.object();
|
|
|
|
}
|
|
|
|
|
|
|
|
rapidjson::Document NetworkResult::parseRapidJson() const
|
|
|
|
{
|
2018-07-14 14:24:18 +02:00
|
|
|
rapidjson::Document ret(rapidjson::kObjectType);
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2018-08-06 21:17:03 +02:00
|
|
|
rapidjson::ParseResult result =
|
|
|
|
ret.Parse(this->data_.data(), this->data_.length());
|
2018-07-07 13:08:57 +02:00
|
|
|
|
|
|
|
if (result.Code() != rapidjson::kParseErrorNone) {
|
2018-08-06 21:17:03 +02:00
|
|
|
Log("JSON parse error: {} ({})",
|
|
|
|
rapidjson::GetParseError_En(result.Code()), result.Offset());
|
2018-07-07 13:08:57 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-08-02 14:23:27 +02:00
|
|
|
const QByteArray &NetworkResult::getData() const
|
2018-07-07 13:08:57 +02:00
|
|
|
{
|
|
|
|
return this->data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|