iPhone SDK 处理来自 Web 服务的数据的理想方式是什么?
目前,我们正在使用 ASP.NET asmx Web 服务与我们的 iPhone 应用程序进行交互。
我的问题是;将服务的响应转换为易于在 Obj-C 中管理的对象的最理想方式是什么。
目前,我们已经定义了一个类,其中包含所有方法(GetSomethingById),然后使用 json 框架将 JSON 字符串转换为 JSON 对象。然后使用“initWithJSON:(id)theJson”构造函数构造适当的类。
问题是......我们似乎处于一场持续不断的战斗中,因为某些类喜欢自动释放(因此我们混合了保留对象([...retain])和普通类。这很完美,但我们感到不安Leaks 工具!
我见过一些涉及使用 Core Data 的解决方案。总而言之:
- 将 Web 服务
- “序列化”为适当的数据结构(类)<- 这是麻烦的部分
有人可以推荐一个明智的解决方案吗?
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:
- Consume web service
- "Serialize" into an appropriate data structure (class) <- This is the troublesome part
Can anyone recommend a sane solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,最好的选择是向服务提出请求。让它返回 JSON 响应。根据接收到的数据创建所需类的实例并使用接收到的数据加载其属性。几乎就是你已经在做的事情。
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.