2013-07-26 3 views
0

저는 BlackBerry 10 개발에 익숙하지 않으며 RESTful 서비스에서 데이터를 가져 오려고하지만 어떻게 할 수 있는지 잘 모릅니다 ... 누군가 가능한지 확인하십시오. 도와 줘, 좋을거야. Blackberry 설명서의 네트워크 액세스에 대한 모든 설명서를 읽었지만 시작할 방법을 알 수 없으며 일부 샘플을 시도했지만 문제가 해결되지 않았습니다.RestFul API를 사용하여 Blackberry 10 응용 프로그램에서

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

이 내가 시도한다 main.qml

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(); 
} 

app.cpp ..

가 감사합니다 ... 도와주세요,하지만 제발 내 Rest JSON 데이터를 되 돌린다. 나는 그것을 얻고 싶다. 그러나 나는 어떻게되는지 모른다. 위의 샘플을 생각해 보았지만, ge 할 수 없다. 이에 I'am 새로운, 그것을 마에 ..

이 제발 도와주세요 ... 감사합니다 ...

+0

무엇을 시도 했습니까? 작동하지 않는 것은 무엇입니까? 코드를 보여 주시면 도와 드리겠습니다. – LuigiEdlCarno

+0

문제가 단지 JSON을 읽었지만 코드가 XML을 위해 작동하는 것이라면,''JsonDataAccess''로 채워진''GroupDataModel''에 의해''XmlDataModel''을 교환해야합니다. 필요한 모든 것은 https://developer.blackberry.com/cascades/documentation/device_platform/data_access/working_with_json.html –

+0

감사합니다 ... 내 문제가 해결되었습니다 .... 감사합니다 .... – Joe0588

답변

1

문제가, 당신은 것입니다 당신이 JSON을 읽고 있지만, 코드가 XML을 위해 노력하고 단지 인 경우 XmlDataModelGroupDataModel (으)로 교환해야합니다 (JsonDataAccess). 필요한 모든 것이 문서화되어 있습니다 here.