iPhone SDK 处理来自 Web 服务的数据的理想方式是什么?

发布于 2024-09-12 10:41:08 字数 473 浏览 5 评论 0原文

目前,我们正在使用 ASP.NET asmx Web 服务与我们的 iPhone 应用程序进行交互。

我的问题是;将服务的响应转换为易于在 Obj-C 中管理的对象的最理想方式是什么。

目前,我们已经定义了一个类,其中包含所有方法(GetSomethingById),然后使用 json 框架将 JSON 字符串转换为 JSON 对象。然后使用“initWithJSON:(id)theJson”构造函数构造适当的类。

问题是......我们似乎处于一场持续不断的战斗中,因为某些类喜欢自动释放(因此我们混合了保留对象([...retain])和普通类。这很完美,但我们感到不安Leaks 工具!

我见过一些涉及使用 Core Data 的解决方案。总而言之:

  1. 将 Web 服务
  2. “序列化”为适当的数据结构(类)<- 这是麻烦的部分

有人可以推荐一个明智的解决方案吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜未央樱花落 2024-09-19 10:41:08

在我看来,最好的选择是向服务提出请求。让它返回 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文