0

이 어떤 URL에서 내 JSON 텍스트입니다 http://www.example.com/json.php구문 분석 JSON ++ 블랙 베리 10

어느 한 내가이 JSON을 구문 분석 어떻게 말해 그것은 할 수 있도록 사용자의 ListView에 배열에 모달를 넣을 수 있습니다하십시오 ?

이전에 iOS 개발자였던 Blackberry 개발을 처음 접했음을 알려드립니다.

나는이 link을 확인했지만 실행할 수 없습니다.

완벽한 솔루션 (예 또는 사용법)이있는 사용자가있는 경우 도와주세요.

JSON의 샘플을 developer.blackberry.com에서 다운로드했지만 실행할 수 없습니다.

은 또한 그것은 모든 JsonDataAccess의 문서에 설명 된 것이 link

{ 
    "status": "success", 
    "result": [ 
     { 
      "offer_id": "456", 
      "member_id": "648", 
      "offer_type": "printable", 
      "cat_name": "Health & Wellbeing", 
      "price": "50", 
      "discount": "20% Off.", 
      "title": "20% Off", 
      "quantity": "200", 
      "details": "Enjoy 20% Off any Service.", 
      "coupon_code": "45600010106", 
      "company_logo": "http://beta/files/offers/logos/", 
      "offer_image": "http://beta/files/offers/images/f4d118737e_image_456.jpg", 
      "bc_image": "http://beta/files/offers/qrcodes/qrcouponid_45600010106.png", 
      "company_address1": "Oud Metha - Mohammed Saeed Hareb Bldg. Opp. American Hospital", 
      "company_address2": "Not Available", 
      "company_city": "Not Available", 
      "company_phone": "04 357 6738 Mob: 509284567", 
      "location": "Oud Metha", 
      "company_name": "Golden House Gents Spa Club", 
      "merchant_name": "Golden House Gents Spa Club", 
      "url": "http://google.com", 
      "date_end": "2013/12/30", 
      "date_start": "2013/07/25", 
      "condition": "1. Cannot be Combined with any other offer.\r\n2. Advance booking required.\r\n3. This Voucher must be Mentioned during time of Booking.\r\n4. Not Valid on Thurs & Sat.\r\n5. Expires 31st December 2013.", 
      "rating": "0", 
      "latitude": "25.2374", 
      "longitude": "55.3117" 
     } 
    ] 
} 

답변

3

에서 그 질문을 기록했다. 다음과 같이해야합니다 :

// Create a data model with sorting keys for title 
GroupDataModel *model = 
    new GroupDataModel(QStringList() << "title"); 

// Load the JSON data 
JsonDataAccess jda; 
QVariant list = jda.load("yourfile.json")["result"].toVariantList(); 

// Add the data to the model 
model->insertList(list.value<QVariantList>()); 

// Add your model to a ListView 
listView->setDataModel(model); 
+1

내가 뭘 배열을 정렬 할 해달라고합니다. 하지만 결과를 웹 서비스에서 온 것으로 보여주고 싶습니다. 나는이 GroupDataModel을 시도했다 * model = 새로운 GroupDataModel(); 하지만 역순으로 표시하고 있습니다. –

+1

키를 지정하지 않고 순서를 바꾸면''sortedAscending''을 반대로 바꾸면됩니다 (https://developer.blackberry.com/cascades/reference/bb__cascades__groupdatamodel.html). # property-sortedascending) 속성을 사용합니다. –

1

이것은 QML 방식이며, C++ 코드를 건드릴 필요가 없습니다.

먼저 QML 파일에서 목록보기를 만들어야합니다.

ListView { 
     id: listData 
     dataModel: ArrayDataModel { 
      id: theDataModel 
     } 
     .... 
} 

이제 listview에 json 파일의 데이터를 채울 수 있습니다. 서버에 전화를 걸면 요청을 보내려합니다.

  function sendRequest() { 
       console.log("DEBUG: sending request"); 
       var request = new XMLHttpRequest(); 
       request.onreadystatechange = function() { 
        // Need to wait for the DONE state or you'll get errors 
        if (request.readyState === XMLHttpRequest.DONE) { 
         if (request.status === 200) { 
          // if response is JSON you can parse it 
          var response = JSON.parse(request.responseText); 

           theDataModel.append({ 
            "offer_id": response.result.offer_id, 
            "member_id": response.result.member_id, 
            "offer_type": response.result.offer_type 
           }); 
          } 

        } else { 
          // Error 
          console.log("DEBUG: Status: " + request.status + ", Status Text: " + request.statusText);      
        } 
       } 
       // POST/GET request 
       request.open("GET", "http://www.example.com/json.php", true); 
       request.setRequestHeader("Accept", "application/json"); 
       request.send(); 
      } 

그리고 값을 표시하기 위해, 당신은 StandardListItem를 사용할 수 있습니다

StandardListItem { 
        title: ListItemData.offer_id 
        description: ListItemData.offer_type 
        status: ListItemData.member_id 
       }