02-07-2013 03:36 AM - edited 02-07-2013 03:41 AM
Hi, in my app I receive a reply from server which is JSON data. The reply is contained in the following form: QNetworkReply* reply. In my code, if I call:
void JSONSample::requestFinished(QNetworkReply* reply)
mFile->write(reply->readAll()); mFile->flush(); mFile->close(); qDebug() << "\n File opened";
I manage to successfully write the JSON contents that I received on the server to a file.
But, if I just try to read the contents of reply into a buffer I get an empty string, since an empty string is printed by qDebug() as below.
const QByteArray response(reply->readAll()); qDebug() << response;
what can I be doing wrong???
ps. And also one question. As I mentioned there is JSON data contained in the "reply". Of course I know
nothing about its structure in advance (i.e., whether it starts with an array or just elements -- I just want to be able to read the whole JSON file regardless of what structure it has. How is it possible to do this?). this sample here: https://developer.blackberry.com/cascades/document
pps. For instance, I have code:
const QByteArray response(reply->readAll()); qDebug() << response; JsonDataAccess jda; QVariantMap results = jda.loadFromBuffer(response).toMap();
Is this the right way to do it ???? How to traverse the whole "results" now ????