mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
Ref T304, "no throw" JSON functions
This commit is contained in:
@@ -123,6 +123,7 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::JsonByMetaClass::convertFromJson
|
||||
//! \throws CJsonException
|
||||
void convertFromJson(const QJsonObject &json)
|
||||
{
|
||||
derived().clear();
|
||||
@@ -167,6 +168,25 @@ namespace BlackMisc
|
||||
return obj;
|
||||
}
|
||||
|
||||
//! Static version of convertFromJson
|
||||
static Derived fromJsonNoThrow(const QString &jsonString, bool acceptCacheJson, bool &success, QString &errMsg)
|
||||
{
|
||||
success = false;
|
||||
Derived obj;
|
||||
try
|
||||
{
|
||||
if (jsonString.isEmpty()) { return obj; }
|
||||
const QJsonObject jsonObj = acceptCacheJson ? Json::swiftDataObjectValue(jsonString) : Json::jsonObjectFromString(jsonString);
|
||||
obj.convertFromJson(jsonObj);
|
||||
success = true;
|
||||
}
|
||||
catch (const CJsonException &ex)
|
||||
{
|
||||
errMsg = ex.toString("JSON conversion");
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
//! Call convertFromJson, catch any CJsonException that is thrown and return it as CStatusMessage.
|
||||
CStatusMessage convertFromJsonNoThrow(const QJsonObject &json, const CLogCategoryList &categories, const QString &prefix); // implemented in statusmessage.h
|
||||
|
||||
|
||||
Reference in New Issue
Block a user