feat(uploader): extend JSON selectors (#6193)
This commit is contained in:
@@ -42,6 +42,25 @@ QJsonArray NetworkResult::parseJsonArray() const
|
||||
return jsonDoc.array();
|
||||
}
|
||||
|
||||
QJsonValue NetworkResult::parseJsonValue() const
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
|
||||
return QJsonValue::fromJson(this->data_);
|
||||
#else
|
||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(this->data_));
|
||||
if (jsonDoc.isArray())
|
||||
{
|
||||
return jsonDoc.array();
|
||||
}
|
||||
if (jsonDoc.isObject())
|
||||
{
|
||||
return jsonDoc.object();
|
||||
}
|
||||
|
||||
return {}; // undefined
|
||||
#endif
|
||||
}
|
||||
|
||||
rapidjson::Document NetworkResult::parseRapidJson() const
|
||||
{
|
||||
rapidjson::Document ret(rapidjson::kObjectType);
|
||||
|
||||
@@ -23,6 +23,13 @@ public:
|
||||
/// Parses the result as json and returns the root as an array.
|
||||
/// Returns empty object if parsing failed.
|
||||
QJsonArray parseJsonArray() const;
|
||||
|
||||
/// Parses the result as json and returns the root as a generic value.
|
||||
/// Returns empty object if parsing failed.
|
||||
///
|
||||
/// In Qt 6.9+, this will parse scalar values as well.
|
||||
QJsonValue parseJsonValue() const;
|
||||
|
||||
/// Parses the result as json and returns the document.
|
||||
rapidjson::Document parseRapidJson() const;
|
||||
const QByteArray &getData() const;
|
||||
|
||||
Reference in New Issue
Block a user