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
Highlighted
Developer
Posts: 39
Registered: ‎08-15-2013
My Device: Blackberry 10
My Carrier: XL
Accepted Solution

Problem parsing JSON Array to ListView

I need some help to parsing JSON Array to ListView.

I have no problem to parse this JSON 

[
    {
        "id": "123",
        "name": "KFC",
        "contact": {
            "phone": "+1175757",
            "twitter": "kfc"
        }
    }

 to this qml :

 

import bb.cascades 1.0
import bb.data 1.0
Page {
    content: ListView {
        id: listView
        dataModel: dataModel
        listItemComponents: [
            ListItemComponent {
                type: "item"
                Container {
                    verticalAlignment: VerticalAlignment.Center
                    Container {
                        horizontalAlignment: HorizontalAlignment.Fill
                        verticalAlignment: VerticalAlignment.Center
                        layout: DockLayout {
                        
                        }
                        Container {
                            horizontalAlignment: HorizontalAlignment.Fill
                            verticalAlignment: VerticalAlignment.Center
                            topPadding: 20
                            layout: StackLayout {
                                orientation: LayoutOrientation.LeftToRight
                            }
                            Container {
                                verticalAlignment: VerticalAlignment.Center
                                leftMargin: 30
                                Label {
                                    bottomMargin: 0
                                    bottomPadding: 0
                                    text: ListItemData.name
                                    verticalAlignment: VerticalAlignment.Center
                                    textStyle {
                                        base: SystemDefaults.TextStyles.TitleText
                                        fontWeight: FontWeight.Normal
                                    }
                                }
                            }
                        }
                    }
                    Divider {
                    }
                }
            }
        ]
    }
    attachedObjects: [
        GroupDataModel {
            id: dataModel
        },
        DataSource {
            id: dataSource
            source: "myjson.json"
            onDataLoaded: {
                dataModel.insertList(data)
            }
        }
    ]
    onCreationCompleted: {
        dataSource.load(); 
    }
}

 but i don't know how to work with this type of JSON :

{
    "meta": {
        "code": 200
    },
    "response": {
        "myplace": [
            {
                "id": "123",
                "name": "KFC",
                "contact": {
                    "phone": "+1657465",
                    "twitter": "kfc"
                }
            }
        ]
    }
}

 can anybody help please !

Developer
Posts: 38
Registered: ‎01-13-2013
My Device: BlackBerry Z10, Q10
My Carrier: Claro (Brazil)

Re: Problem parsing JSON Array to ListView

The problem is that DataSource will convert your JSON to a QVariantMap, not to a QVariantList, as required by GroupDataModel::insertList().  Try this:

 

        DataSource {
            id: dataSource
            source: "myjson.json"
            onDataLoaded: {
                dataModel.insertList(data.response.myplace)
            }
        }

 

 

 

Developer
Posts: 39
Registered: ‎08-15-2013
My Device: Blackberry 10
My Carrier: XL

Re: Problem parsing JSON Array to ListView

thanks, its solve my problem