02-06-2013 08:33 AM - edited 02-06-2013 08:34 AM
Imagine I have some JSON response. And I also have some custom classes MyCustomClass1 and MyCustomClass2.
I know we have a JSON parser on BB 10 SDK (JsonDataAccess). I am curious if BlackBerry 10 has a way (maybe a class? or a library?) that also allows to automatically convert this JSON response to objects of my custom classes? (e.g., MyCustomClass1 and MyCustomClass2).
I found some library which is supposed to do this: http://fossil.wanderinghorse.net/repos/nosjob/inde
(it's description says: "Easy parsing of JSON string data (from arbitrary input iterators) into C++ objects.") -- but I was curious if there is a BlackBerry way to do this? Plus I am not sure yet if I can use this library on BB 10.
Thanks for your input.
02-07-2013 03:24 AM
3 weeks ago - last edited 3 weeks ago
Is QJon available for native? I'm porting a library that uses it but I can't figure out how to resolve this dependancy with what's in the sdk?
How do you include it?
2 weeks ago
No, there is no automatic way to do that in C / C++. What you could do is use JsonDataAccess to load the data and traverse the QVariant data returned and as you encounter certain types of data, instantiate the custom classes they map to and ppopulate the classes with data from the QVariant objects. It will require some work on your part to ensure that there are things like a className attribute to indicate which class this maps to and perhaps you can pass in the object directly to that class so that it can read what it needs directly from the QVariant object, which will make the loading function more lightweight (it then only needs to know what to instantiate from the top level of embedded objects).
Hope that helps.