1.how to use json web service in blackberry cascades.
2.i need to get data from url link into qml page. give suggession with some sample if possible.
3.my web service link contains array type
for eg: { "address":["area": "chn", "city": "ght"]}
4.description: json link --> 192.168.1.251:410/Mobile/Service1.svc/english/Category?CountryID=1
5.by using above link please tell how to retrive data from json webservice in cascades.. i need answer in cascades method..
Right. Well this is really a two part question. First is how to make a request and receive a reply, and second is how to parse the JSON; luckily, Cascades has you covered for both cases.
To make a request:
QNetworkAccessManager qNam;
QNetworkRequest req("192.168.1.251:410/Mobile/Service1.svc/english/Category?CountryID=1");
QNetworkReply *reply = qNam.get(req);
connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
Then define the onFinished slot as so:
void ClassName::onFinished() {
QNetworkReply *reply = dynamic_cast<QNetworkReply*>(sender());
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200) {
JsonDataAccess jda;
QVariantMap map = jda.loadFromBuffer(reply->readAll()).toMap();
QVariantList addresses = map["address"].toList();
foreach(QVariant var, addresses) {
QVariantMap addressMap = var.toMap();
qDebug() << "Area is " << addressMap["area"].toString();
qDebug() << "City is " << addressMap["city"].toString();
}
}
else {
qDebug() << "Server returned code " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()
}
}
For this to work, this method has to be marked in the class as a Q_SLOT
.