Is it possible to use key mapping with the following JSON structure or are we going to have to perform looping through values manually? Examples would be great. Their rest api doesn’t really map real world objects into a standard object structure, but just modeled after the XML attributes. 🙁
THINGS{
"lastModifiedDate": "2012-02-23-08.43.16.916000",
"myList": [{
"attributeList": [
{"id": "","name": "Content Level","val": "Introductory"},
{"id": "","name": "Session Type","val": "Business Overview"},
{"id": "20110616053537016","name": "Speaker","val": "Jim Kim, Company1"},
{"id": "20110616053526559","name": "Speaker","val": "Bob Ironman, Company2"},
{"id": "20110803145027914","name": "Speaker","val": "Kristine Thomas, Company3"},
{"id": "","name": "Room","val": "Banyan"},
{"id": "","name": "Industry","val": "Cross Industry"},
{"id": "","name": "Loc","val": "Stadium I"},
{"id": "","name": "Topic Tag","val": "CMS Systems"},
{"id": "","name": "Status","val": "Accepted"},
{"id": "","name": "Sub-Event","val": "Leadership"},
{"id": "","name": "Session","val": "LVI"},
{"id": "","name": "SubTrack","val": "None"},
{"id": "","name": "Track","val": "Business Value Outsourcing"}
],
"active": true,
"desc": "This is a really cool thing",
"end": "16:00",
"id": "2011080146112",
"num": "1002A",
"start": "15:00",
"title": "The thing title"
}
]
}
Yes it is possible with RestKit.
You can get all documentation you need reading this article from the official wiki and here you have an explanation for doing what you need. Hope this helps you!
First you will need three objects for each entity, one for the ThingsList, another for representing one Thing and another for representing one ThingAttribute. Let’s start by the most basic element, the ThingAttribute:
SOAttribute.h
SOAttribute.m
This will let you to represent this part of the JSON:
Now we will define the Thing as follows:
SOThing.h
SOThing.m
As you can notice, you have to define the attributeList as an NSArray. RestKit automatically will know that you need to receive a list of attributes there. So we have defined the following structure:
Finally you define the Thing List as follows:
SOThingList.h
SoThingList.m
As before, we need a list of Things so we define myList as an NSArray.
Now, that was easy, here comes the magic where you indicate to RestKit how to map each entity.
On your App Delegate put the following code:
After all the above, you can get your Thing List with the following method using blocks:
SomeObject.m
And you use it like this…