Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 43
Registered: ‎07-23-2013
My Device: Z10
My Carrier: Vodacom
Accepted Solution

Json web service data not returning

[ Edited ]

I have created an app with a local (in assets forlder) sample test json file called "contacts.json" as below, just to test if I have any data returning. The data returns in a listview without a problem.

 

[{ "id":1, "firstname": "Mike", "lastname": "Chepesky", "title": "Sr. Editor",
  "image": "images/data/mike_chepesky.png", "active": true, "gender": "m" },
{ "id":2, "firstname": "Westlee", "lastname": "Barichak", "title": "Talent Scout",
  "image": "images/data/westlee_barichak.png", "active": true, "gender": "m" }]

 I then changed the source to "http://...." which is a link that is valid and I checked, and it does return data in a normal web browser (firefox). But it will not return in my app.

 

What I noticed is that the difference between the local json file and the web service return, the web service does not return the square brackets "[...]" around the json.. I suspect that may be the problem? If so, how do I manipulate the datasource in my app to incorporate the brackets? This is the actual returned data (no square brackets)..

 

{"status":"successful","current_version":"1.1.1","latest_version":"1.2.0.0","details":"1. Item A 2. Item B 3. Item C","type":"Force update"}

 Thank you.

Developer
Posts: 43
Registered: ‎07-23-2013
My Device: Z10
My Carrier: Vodacom

Re: Json web service data not returning

[ Edited ]

If it helps.. here is my QML code (formatting excluded for easier reading)..

 

import bb.cascades 1.0
import bb.system 1.0
import bb.data 1.0


Dialog {

    Container {
        layout: DockLayout {
        }

        Container {
                ListView {
                    id: featuresListView
                    dataModel: dataModel

                    listItemComponents: [
                        ListItemComponent {
                            type: "item"
                            Container {
                                Label {
                                    text: ListItemData.status
                                }
                                 Label {
                                    text: ListItemData.details
                                } 
                            }
                        }
                    ]
                } //end listview

        onCreationCompleted: {
            dataSource.load();
        }

        attachedObjects: [
            GroupDataModel {
                id: dataModel
                grouping: ItemGrouping.None
            },
            DataSource {
                id: dataSource           
                type: DataSourceType.Json
                
                //source: "contacts.json" // THIS SOURCE WAS USED TO TEST WITH LOCAL JSON FILE.. AND IT WORKS
                source: "http://..**ACTUAL URL HERE**"
                
                onDataLoaded: {
                    dataModel.clear();
                    dataModel.insertList(data);
                    console.log(data);
                }
            }

        ]
    }
}

 

Developer
Posts: 236
Registered: ‎10-19-2012
My Device: Playbook, BB10DevAlphaB/C, Z10
My Carrier: Sonera, Saunalahti

Re: Json web service data not returning

If I'm not mistaken, your local json file contains an array of objects, and the one you load from your server contains just one object.
If so, you can't call insertList(data), use insert(data)


Kaj-Michael Lang, Home.
Author of: Onki and RetroPlayer
Highlighted
Developer
Posts: 43
Registered: ‎07-23-2013
My Device: Z10
My Carrier: Vodacom

Re: Json web service data not returning

OnionGarlic, I could send you a bottle of oil and vinegar, so you can make a salad right now hahaha.. that's how happy I am IT WORKED!!

 

You are quite right, the server json is a single object.