Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
ddluk
Posts: 212
Registered: ‎10-02-2010
My Device: Z10 and Z30
My Carrier: Play and Plus
Accepted Solution

JsonDataAccess reporting error in JSON even it's valid

I've got a problem with parsing JSON which I'm getting from QNetworkReply. I checked on http://json.parser.online.fr/beta/ if json is valid and it is:

 

{
	"status": 0,
	"objects": [{
		"id": "i_53909cc3eeafd",
		"name": "picture1",
		"location": [{
			"x": -5,
			"y": 126
		}, {
			"x": 266,
			"y": 126
		}, {
			"x": 269,
			"y": 396
		}, {
			"x": -5,
			"y": 400
		}]
	}]
}

 I'm using following code:

 

void ApplicationUI::onRequestFinished(QNetworkReply* reply) {

    QString response = QString::fromUtf8(reply->readAll());

	if(reply){
	    if(reply->error() == QNetworkReply::NoError) {

	        JsonDataAccess jsonDataAccess;
	        QVariant list = jsonDataAccess.loadFromBuffer(response);
	        if (jsonDataAccess.hasError()) {
	            DataAccessError error = jsonDataAccess.error();
	            qDebug() << "JSON loading error: " << error.errorType() << ": " << error.errorMessage();
	            return;
	        }
	    } else {
	        qDebug() << "Network error!";
	    }
	}

reply->deleteLater();
}

 

Everyt time I'm receive reply  jsonDataAccess is displaying me error:

 

JSON loading error:  3 :  "* Line 1, Column 1
  Syntax error: value, object or array expected.
" 

 

The second problem is fact that I'm not able to get access to values from this json reply. I tried a lot of possibilities and I'm always getting empty results.

Please use plain text.
Developer
ddluk
Posts: 212
Registered: ‎10-02-2010
My Device: Z10 and Z30
My Carrier: Play and Plus

Re: JsonDataAccess reporting error in JSON even it's valid

[ Edited ]

Ok, Problem is now solved. I realized that in my QNetworkAccessManager I have had following line:

request.setRawHeader(QString("Accept-Encoding").toAscii(), QString("gzip,deflate").toAscii());


Which was breaking my JSON.

Please use plain text.