mercredi 24 août 2016

How to convert json object to QObject?

Json structure is C++ struct-like (struct or array of sturcts, arrays and basic types). I need to convert JSON object to specified QObject with specified properties (by QObject fields).

For example, the json:

{
  "name": "Andrew",
  "age" 33,
  "identifiers": [32, 45, 67, 78],
  "more": {
     "gps": "44.9064', W073° 59.0735'",
     "valid": true
  }
}

QObjects:

class FMoreInfo : public QObject {
   Q_OBJECT

   Q_PROPERTY( QString gps );
   Q_PROPERTY( bool valid );
}

class FPersonInfo : public QObject {
   Q_OBJECT

   Q_PROPERTY( QString name );
   Q_PROPERTY( int32 age );
   Q_PROPERTY( QVector<int32> identifiers );
   Q_PROPERTY( FMoreInfo more );

}

JSON is a string and I need convert it by one template function to FPersonInfo. Is there known algorithms?





Aucun commentaire:

Enregistrer un commentaire