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

Reply
Developer
marioi
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.

Please use plain text.
Developer
marioi
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);
                }
            }

        ]
    }
}

 

Please use plain text.
Developer
oniongarlic
Posts: 72
Registered: ‎10-19-2012
My Device: Playbook, BB10DevAlphaB
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)
Please use plain text.
Developer
marioi
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 :Clap: IT WORKED!!

 

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

Please use plain text.