开发者

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

开发者 https://www.devze.com 2023-01-10 01:49 出处:网络
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 a

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号