iphoneobjective-ccocoa-touchweb-servicesjson-framework

What is the ideal way in the iPhone SDK to handle data coming from a web service?


Currently, we're using ASP.NET asmx web services to interface with our iPhone application.

My question is; whats the most ideal way of converting the responses from the services into objects which are easy to manage in Obj-C.

At present, we have defined a class which has all the methods in it (GetSomethingById), this then converts the JSON string to a JSON object using the json-framework. Then constructs the appropriate class with an "initWithJSON:(id)theJson" constructor.

The problem is... we seem to be at a constant battle as certain classes like to be autoreleased (therefore we have a mix of retained objects ([... retain]) and normal classes. This works perfectly but we're upsetting the Leaks tool!

I've seen a few solutions involving the use of Core Data. In summary:

  1. Consume web service
  2. "Serialize" into an appropriate data structure (class) <- This is the troublesome part

Can anyone recommend a sane solution?


Solution

  • In my opinion your best bet is to request something to the service. Have it return a JSON response. Depending on the received that create an instance of the desired class and load its properties with the data received. Pretty much what you are already doing.