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
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook
Accepted Solution

Differnt List types with JSON

I've created a flat list view using the Grouping:None technique mentioned here:

http://supportforums.blackberry.com/t5/Cascades-Development/ListView-no-header/td-p/1737097/highligh...

 

I'm trying to change my list to display differently based on the type, as indicated in the JSON.  My first category in my JSON is type , but I can't seem to get that to display the list correctly.

eg.

{"type":"image", "url":"http:\\whatever"}

 

I've been able to do it in XML but can't do it in JSON.  Anyone have any suggestions?

---
If you find my post helpful please "like" it and "accept as a solution"
BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer

Re: Differnt List types with JSON

[ Edited ]

You want to define a function itemType.  See samples weatherguesser and bucketlist.

 

Stuart

Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook

Re: Differnt List types with JSON

Both of those examples only base it upon index.length.   There is no example that includes more complex comparisons based on the actual data content.

 

So back to my example

JSON is formatted this way:

{"type":"image", "url":"http:\\whatever"}

{"type":"video", "url":"http:\\whatever"}

 

 I was struggling with how to access the string variable with the JSON and then how to do a string comparison.  How do I complete the code below?

 

itemType(data,IndexPath)

{

  // if type is "image" then 

                   return = " image"

 else

  // if type is "image" then 

                  return ="video"

}

---
If you find my post helpful please "like" it and "accept as a solution"
Developer
greenback
Posts: 535
Registered: ‎10-17-2010
My Device: (BlackBerry Z10)-> Q10/Passport Dual Use

Re: Differnt List types with JSON

BUMP.

I think a lot more developers need help with parsing different types of JSON data structures, and background on how to do this in C++/Qml. I think that super apps or custom applications launching on BB10 will call apis; the apis will be internal to their application, or 3rd party apis.

 

BUMP

Thanks!

 

 

Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook

Re: Differnt List types with JSON

In C++ I've been able to output the format of  data(indexPath).

 

How do I access the "type" in the QVariant?

 

QVariant(QVariantMap, QMap(("URL", QVariant(QString, "../../../shared/camera/IMG_00000005.jpg") ) ( "infoText" ,  QVariant(QString, " ") ) ( "thumbURL" ,  QVariant(QString, "../../../shared/camera/IMG_00000005.jpg") ) ( "type" ,  QVariant(QString, "item") ) )  )

---
If you find my post helpful please "like" it and "accept as a solution"
Developer
soaman
Posts: 849
Registered: ‎03-03-2011
My Device: Z10

Re: Differnt List types with JSON

Use methods like toMap(), toInt(), toString(), etc.

The method returns 0, if it can't cast.
--------------------------------------------------------------------------------------
Leader of Ljubljana BlackBerry Developer Group
BlackBerry Certified Builder for Native Application Development
Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook

Re: Differnt List types with JSON

Thanks!

 

Had to use a couple of them in fact!

 

data(indexPath).toMap().value("type").toString() = "item"

---
If you find my post helpful please "like" it and "accept as a solution"
Developer
Dredvard
Posts: 160
Registered: ‎01-27-2012
My Device: Playbook

Re: Differnt List types with JSON

An alternate method in QML is to do the following

 

  

var chosenItem = dataModel.data(indexPath);
return chosenItem.type

 

---
If you find my post helpful please "like" it and "accept as a solution"