I am calling a web service which returns dictionary to render the graph. Dictionary structure is
{"1":0,"2":0,"8":0,"9":2,"10":3,"11":0,"12":0}
The problem is keys are dynamic values like 1,2,3 etc which indicates month. Is it possible to represent this in JsonModel?
See you cant create properties at run time as per response structure. But we can smartly use pre-defined things and achieve this. Do following steps:
Create one model class. So your
MyCustomModel.hfile will look like thisThis will be your
MyCustomModel.mfileNow lets suppose {"1":0,"2":0,"8":0,"9":2,"10":3,"11":0,"12":0} is
NSDictionaryand lets say its name isdictionaryResponseNow do this stuffs:
So your responseKeys will have all keys of response like ["1","2","8","9","10","11","12",]
Now you can iterate loop and create
NSMutableArrayof model objects asNow
arrayMonthListwill consist of objects of type MyCustomModelSo you can use it and parse it. Even you can use it to show on
UITableView. Following code is written to print values of model properties, you can customise at your expected level.