get multiple data from json with QT C++ -


i need multiple data json, first part can read, json inside can't it.

so data api:

enter image description here

my code in c++/qt it's next:

qstring jsonfunctions::getunits(qstring token_type, qstring access_token) {     qstring lista;     qeventloop eventloop;     qnetworkaccessmanager mgr;     qobject::connect(&mgr, signal(finished(qnetworkreply*)), &eventloop, slot(quit()));      qjsonobject json;      qnetworkrequest request(qurl("https://myurl/api/v2/units"));     request.setheader(qnetworkrequest::contenttypeheader, "application/json");     //request.setrawheader("content-type", "application/json");     request.setrawheader("accept", "application/json");     qstring sing =  token_type + " " + access_token;     request.setrawheader("authorization", sing.toutf8());      qsslconfiguration conf = request.sslconfiguration();     conf.setpeerverifymode(qsslsocket::verifynone);     request.setsslconfiguration(conf);      qnetworkreply *reply = mgr.get(request);     eventloop.exec();      qstring strreply = (qstring)reply->readall();     qdebug() << "reply" << strreply;     qdebug() << "code" << reply->attribute(qnetworkrequest::httpstatuscodeattribute).toint();      qjsondocument jsonresponse = qjsondocument::fromjson(strreply.toutf8());     qjsonarray jsonarray = jsonresponse.array();      qjsonobject jsonobject = jsonresponse.object();     qvariantmap mainmap = jsonobject.tovariantmap();     qvariantlist phraselist = mainmap["data"].tolist();      qjsonobject jsonobjs = qjsonobject::fromvariantmap(mainmap);     qjsonarray dataobject = jsonobjs.value("data").toarray();      for(int = 0; < dataobject.count(); i++){         qjsonobject temp = dataobject[i].toobject();         units unitstemp;          unitstemp.id = temp.value("ac_role_name").tostring();         unitstemp.description = temp.value("description").tostring();         unitstemp.thing_name = temp.value("thing_name").tostring();         unitstemp.serial_number = temp.value("serial_number").tostring();         unitstemp.access_key = temp.value("access_key").tostring();         unitstemp.state = temp.value("state").toint();         unitstemp.location_id = temp.value("location_id").tostring();         unitstemp.billing_id = temp.value("billing_id").tostring();         unitstemp.created_at = temp.value("created_at").tostring();         unitstemp.update_at = temp.value("update_at").tostring();         unitstemp.nickname = temp.value("nickname").tostring();         unitstemp.image = temp.value("image").tostring();         unitstemp.status = temp.value("status").tostring();         unitstemp.ac_role_name = temp.value("ac_role_name").tostring();          //qjsonvalue sitevalue = temp.value("location").toarray();         //qjsonobject locationobject = sitevalue.toobject();          //how location data ?          qjsonarray dataobjectz = temp.value("location").toarray().at(0).toarray();          //unitstemp.locations.address = locationobject.value("address").tostring();          //devo prendere le location          qstring debug;     }      return lista; } 

i've tried code , codes...but how location data ?? don't found solution works me. idea ? i'm new in qt , c++. thanks.

the solutions it's:

qjsonobject locationobject = temp["location"].toobject(); qstring addressfromlocation = locationobject.value("address").tostring(); 

work me


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -