converting JSON object to class
-
hi ,,, can anybody pls suggest me to convert from QJsonObject to class
here i created one object (room=new XperienceRoom();) in DataManager class to use xperience room class ,,
void DataManager::setRoom(QJsonObject response)
{
// room = response;
room=response["room"].toObject();
}QJsonObject DataManager::getRoom()
{
return room;
}here i'am getting error "Assigning to' XperienceRoom *' from inocmpatible type 'QJsonObject'
-
@Dimple
thats not possible directly (the way you tried).
Does the JSON object have the same properties like your class?
If so you will need to copy each property "manually" -
@Dimple said in converting JSON object to class:
hi ,,, can anybody pls suggest me to convert from QJsonObject to class
Here is an example: http://doc.qt.io/qt-5/qtcore-serialization-savegame-example.html
-
i got solution ,,,its a correct way
void DataManager::setRoom(QJsonObject json)
{
QString id =json["_id"].toString();
QString contactid = json["contact_id"].toString();
QString createdate = json["create_date"].toString();
QString createrid = json["creater_id"].toString();
bool deleted = json["deleted"].toBool();
bool finished = json["finished"].toBool();
int historyindex = json["history_index"].toInt();
bool isgroup = json["is_group"].toBool();room->setId(id);
room->setContactId(contactid);
room->setCreateDate(createdate);
room->setCreaterId(createrid);
room->setDeleted(deleted);
room->setFinished(finished);
room->setHistoryIndex(historyindex);
room->setIsGroup(isgroup);}
XperienceRoom* DataManager::getRoom()
{
return room;
} -