c++ - Qt parsing json using network response binary -
alright, found don't understand. making request web service using qtnetworkmanager. reason can't seem go network response jsondoc directly, have cast string , uft8?
void webapiengine::handlenetworkdata(qnetworkreply *networkreply) { //no network error if (!networkreply->error()){ //cast string qstring strreply = (qstring)networkreply->readall(); //this works, jsondoc have json response webpage qjsondocument jsondoc = qjsondocument::fromjson(strreply.toutf8()); //this doesn't work, networkreply->readall() said homecoming qbytearray. qjsondocument jsondoc2 = qjsondocument::frombinarydata(networkreply->readall()); qjsonobject jsonobj = jsondoc.object(); info = jsonobj; } //network error else{ data["error"] = "webapiengine::handlenetworkdata()"; } now can not understand why jsondoc working , jsondoc2 not. can explain?
once qnetworkreply->readall(), qnetworkreply object empty. if phone call qnetworkreply->readall() method again, not anything.
moreover don't understand why converting qbytearray returned qnetworkreply->readall() qstring , converting qbytearray(by calling qstring::toutf8()) give qjsondocument::fromjson function.
you can seek doing this:
qbytearray temp = newreply->readall(); qjsondocument jsondoc = qjsondocument::fromjson(temp); // should work also create sure know content of json document is, i.e. if map (qjsonobject), array(qjsonarray), array of maps or map array value.
c++ json qt binary
No comments:
Post a Comment