Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
QxJson::Converter< T > Struct Template Reference

The Converter template struct acts as an interface that carries details on how to parse JSON to various types. More...

Detailed Description

template<typename T>
struct QxJson::Converter< T >

JSON data can be converted to an object of any type as Converter provides a specialization for that type that contains a corresponding fromJson() function.

By default, conversions are provided for:

Support for additional, non-structural types can be added like so:

class MyType
{
...
};
namespace QxJson
{
template<>
struct Converter<MyType>
{
static Qx::JsonError fromJson(MyType& value, const QJsonValue& jValue)
{
// Assign `value` to complete the conversion
value = //...
// Return an invalid JsonError upon success, or a valid one if an error occurs
return Qx::JsonError();
}
};
}

If a structural type needs to be registered, the QX_JSON_STRUCT and QX_JSON_MEMBER macros should be used instead.

See also
qx-json.h and keygen().

The documentation for this struct was generated from the following file: