If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
robtraf
Posts: 48
Registered: ‎03-27-2011
My Device: BlackBerry Z10
My Carrier: Telstra

Display data from JSON file

Maybe I do not fully understand the 'how to extract data from a JSON file' paradigm or GroupDataModel theory, but I need some help with the following.
The WeatherGuesser sample app's data is provided by a JSON file that has been mocked up to show as an example. It does not obtain 'live' data from a call to HTTP (internet).
In my app i am trying to use some techniques from the sample app including a call to 'live' data. I have managed to obtain the data and I have parsed the JSON file without error. The following data is retrieved:

{ "data": { "current_condition": [ {"cloudcover": "75", "humidity": "94", "observation_time": "04:39 AM", "precipMM": "4.1", "pressure": "1012", "temp_C": "19", "temp_F": "66", "visibility": "4", "weatherCode": "293", "weatherDesc": [ {"value": "Patchy light rain" } ], "weatherIconUrl": [ {"value": "http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png" } ], "winddir16Point": "S", "winddirDegree": "190", "windspeedKmph": "7", "windspeedMiles": "4" } ], "request": [ {"query": "Melbourne, Australia", "type": "City" } ], "weather": [ {"date": "2012-12-14", "precipMM": "16.6", "tempMaxC": "19", "tempMaxF": "67", "tempMinC": "18", "tempMinF": "64", "weatherCode": "266", "weatherDesc": [ {"value": "Light drizzle" } ], "weatherIconUrl": [ {"value": "http:\/\/www.worldweatheronline.com\/images\/wsymbols01_png_64\/wsymbol_0017_cloudy_with_light_rain.png" } ], "winddir16Point": "SSW", "winddirDegree": "204", "winddirection": "SSW", "windspeedKmph": "9", "windspeedMiles": "6" } ] }}

I would like some help on displaying the data. in my app I have the following code:

                listItemComponents: [

                    ListItemComponent {

                        type: "item" 

                        PlaceItem {

                            title: ListItemData.humidity

                            description: ListItemData.visibility

                        }

                    }

                ]

 

PlaceItem formats the UI. I have tried many different combinations but no output is displayed. Could someone help me as I just cant seem to extract the data. If I could just display 1 (one) item from the JSON file would be an achievement!

Thank you.

 

 

Please use plain text.
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Display data from JSON file

What are you putting into your data model? A Qvariantmap of the data object?

You have to access the properties of the qvariantmap like accessors, humidity and visibility are down in the tree at a lower level. if thats exactly what you put in your groupdatamodel it would be something like: ListItemData.data.current_condition[0].humidity
Like all of my posts
Please use plain text.
Developer
robtraf
Posts: 48
Registered: ‎03-27-2011
My Device: BlackBerry Z10
My Carrier: Telstra

Re: Display data from JSON file

Thanks Kyle. I follow your tweets on Twitter, great work!

You have replied before to a smilar post, I just cant get it to work! I am using a QVariantMap. Woul it be useful if you were to take a quick look over the project on Dropbox or similar? I know then that what I put in the code will work!

Please use plain text.
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: Display data from JSON file

sure, if you want to put it up on github or something?
Like all of my posts
Please use plain text.