0

I am new on BlackBerry 10 development and I am trying to get data from a RESTful service, but I don't have any idea how can I do it... Please if somebody can help me, It'll be nice. I have read all the documentation about the Network Access in Blackberry documentation, but I can't get it how to start and I have try some samples but it doesn't solve my problem. Please Help me...

Thank You..

app.cpp

void ApplicationUI::initiateRequest(){
    // Start the activity indicator.
    myActivityIndicator->start();
    myLabel->setVisible(true);
    myLabel->setText("Retrieving contact list ...");
    // Create and send the network request.
    QNetworkRequest request = QNetworkRequest();
    request.setUrl(QUrl("http://developer.blackberry.com/cascades/files/documentation/images/model.xml"));
    myNetworkAccessManager->get(request); 
}

void ApplicationUI::requestFinished(QNetworkReply* reply)
{
    myActivityIndicator->stop();
    myLabel->setVisible(false);

    // Check the network reply for errors.
    if (reply->error() == QNetworkReply::NoError)
    {
        // Open the file and print an error if the file cannot be opened.
        if (!myFile->open(QIODevice::ReadWrite))
        {
            // Report: "Failed to open file"
            return;
        }

        // Write to the file using the reply data and close the file.
        myFile->write(reply->readAll());
        myFile->flush();
        myFile->close();

        // Create the data model using the contents of the file.
        XmlDataModel *dataModel = new XmlDataModel();
        dataModel->setSource(QUrl("file://" + QDir::homePath() + "/model.xml"));

        // Set the new data model on the list.
        myListView->setDataModel(dataModel);
    }
    else
    {
        myLabel->setText("Problem with the network");
    }

    reply->deleteLater();
}

main.qml

Page {
    Container {
            id: cntrListview

            // A list that has two list item components, one for a header
            // and one for contact names. The list has an object name so
            // that we can set the data model from C++ code.
            ListView {
                objectName: "list"
                topPadding: 6.0
                bottomPadding: 6.0
                leftPadding: 6.0
                rightPadding: 6.0

                // The app loads an XML file called model.xml that is used
                // as the data model for the ListView to populate our
                // contact list. This XML file is downloaded in our
                //  app's constructor in the accompanying C++ code.
                dataModel: XmlDataModel {
                }
                listItemComponents: [
                    // The header list item displays a title along with a counter
                    // that displays the number of children. Each child is a name
                    // in the contact list.
                    ListItemComponent {
                        type: "header"
                        Header {
                            title: ListItemData.title
                            subtitle: (ListItem.initialized ? ListItem.view.dataModel.childCount(ListItem.indexPath) : 0)
                        }
                    },
                    // The contact list item displays the name of the contact.
                    ListItemComponent {
                        type: "contacts"
                        StandardListItem {
                            title: ListItemData.title
                        }
                    }
                ]
            }
        }
}

This is I have tried, but my Rest Resturns JSON data, and I would like to get it, but I don't know how, I tried the above sample to get any idea, but I can't get it, I'am new in this..

Please help me.. Thank You...

Joe0588
  • 1
  • 3
  • What have you tried? What is not working? Please show us your code, so we can help you. – LuigiEdlCarno Jul 26 '13 at 07:30
  • If the problem is just that you are reading JSON but your code is working for XML, you'll have to exchange your ``XmlDataModel`` by a ``GroupDataModel`` filled by a ``JsonDataAccess``. Everything you need is documented here: https://developer.blackberry.com/cascades/documentation/device_platform/data_access/working_with_json.html – Marc Plano-Lesay Jul 27 '13 at 01:03
  • I'll post it as an answer, so you can mark your question as solved. – Marc Plano-Lesay Jul 28 '13 at 08:36

1 Answers1

1

If the problem is just that you are reading JSON but your code is working for XML, you'll have to exchange your XmlDataModel by a GroupDataModel filled by a JsonDataAccess. Everything you need is documented here.

Marc Plano-Lesay
  • 6,808
  • 10
  • 44
  • 75