0

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..

Rajesh Loganathan
  • 11,129
  • 4
  • 78
  • 90

2 Answers2

3

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.

Konrad Lindenbach
  • 4,911
  • 1
  • 26
  • 28
1

try this syntax.. if need more get it from here http://qjson.sourceforge.net/usage/

QJson::Parser parser;
bool ok;

QVariantMap result = parser.parse (json, &ok).toMap();
if (!ok) {
  qFatal("An error occurred during parsing");
  exit (1);
}

qDebug() << "encoding:" << result["encoding"].toString();
qDebug() << "plugins:";

foreach (QVariant plugin, result["plug-ins"].toList()) {
  qDebug() << "\t-" << plugin.toString();
}

QVariantMap nestedMap = result["indent"].toMap();
qDebug() << "length:" << nestedMap["length"].toInt();
qDebug() << "use_space:" << nestedMap["use_space"].toBool();