2013-07-26 6 views
0

Je suis nouveau sur le développement de BlackBerry 10 et j'essaye d'obtenir des données d'un service RESTful, mais je n'ai aucune idée comment je peux le faire ... S'il vous plaît si quelqu'un peut aide moi, ça va être sympa. J'ai lu toute la documentation sur la documentation de Network Access in Blackberry, mais je n'arrive pas à la démarrer et j'ai essayé quelques samples mais ça ne résout pas mon problème. Aidez-moi s'il vous plaît ...Travailler avec RestFul Api à partir de Blackberry 10 Application

Merci .. Vous

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 
         } 
        } 
       ] 
      } 
     } 
} 

C'est que j'ai essayé, mais mon Rest Restaure les données JSON, et je voudrais l'obtenir, mais je ne sais pas comment, j'ai essayé l'échantillon ci-dessus pour avoir une idée, mais je ne peux pas ge t il, Je suis nouveau dans ce ..

S'il vous plaît aidez-moi .. Merci ...

+0

Qu'avez-vous essayé? Qu'est-ce qui ne fonctionne pas? S'il vous plaît nous montrer votre code, afin que nous puissions vous aider. – LuigiEdlCarno

+0

Si le problème est juste que vous lisez JSON mais que votre code fonctionne pour XML, vous devrez échanger votre '' XmlDataModel'' par un '' GroupDataModel'' rempli par un '' JsonDataAccess''. Tout ce dont vous avez besoin est documenté ici: https://developer.blackberry.com/cascades/documentation/device_platform/data_access/working_with_json.html –

+0

Merci ... Cela a résolu mon problème .... Merci ... – Joe0588

Répondre

1

Si le problème est que vous lisez JSON mais votre code fonctionne pour XML, vous avoir à échanger votre XmlDataModel par un GroupDataModel rempli par un JsonDataAccess. Tout ce dont vous avez besoin est documenté here.