创建一个JSON解析器/网络对象 [英] Creating a single JSON Parser/Network object
问题描述
我正在寻找的是在帮助我创造什么,我需要我的应用程序设计中做一个更好的概念,正确的方向的一个点。
What I'm looking for is a point in the right direction of helping me create a better concept of what I need to do within my application design.
我试图做的是有一个类,这将使网络请求,IE:的getUser,getTimeline,的getLocation。一旦数据已经通过recieived - (无效)connectionDidFinishLoading:
的JSON(我的应用我使用TouchJSON)来解析数据,并用这些数据返回数组或它的对象。
What I'm trying to do is have a class that will make network requests, IE: getUser, getTimeline, getLocation. Once the data has been recieived via -(void)connectionDidFinishLoading:
have JSON (for my application I'm using TouchJSON) to parse the the data and with that data return an array or object of it.
以上所有我能做的,但我觉得我需要做的是在每一个类创建这导致了很多code,并在该冗余code。
All the above I can do, however I find I need to do it in every class I create which leads to a lot of code, and redundant code at that.
基本上,如果我想要做这种做法现在这是发生了什么粗略演练:
Basically if I want to do this approach now this is a rough walkthrough of what happens:
因此,例如:
- [查看1] - > NetworkActivity对象 - >的getUser
- [NetworkActivity] - >的getUser - >的makeConnection - >的parseObject - >返回对象
- [查看1] - >的getUser方法现已完成,是空的,这反过来又意味着现在我什么都没有表现出
现在我明白,因为使用异步请求IM这就是为什么发生这种情况,但我后一种方法可以做到这一点的方法,而无需创建多个类,基本上做同样的事情。我不是在寻找答案只是一个微调或东西方向是正确的时候,我可以读或尝试将更好地帮助我理解这一点。
Now I understand that because im using Asynchronous request this is why this is happening, however what I'm after is a way to accomplish this approach without having to create several classes that basically do the same thing. I'm not looking for "the answer" just a nudge or a point in the right direction of something I can read or try that would better help me understand this.
此外,我很抱歉,如果这是在所有的混乱,我试图来形容它作为最好的,我可以,但请明白 - 我有点在这一切弄得自己
Also I'm sorry if this was at all confusing, I tried to describe it as best as I could, but please do understand - I'm kinda confused at it all myself!
推荐答案
在看看马特Gemmell的 MGTwitterEngine 这是如何开发一个客户端针对特定的API,Twitter的一个很好的例子。如果你知道服务工具REST Web服务,那么你也可以看看的 iPhone on Rails的项目,它实现通用控制器。您提供的模型和控制器会完成剩余的工作。
Take a look at Matt Gemmell's MGTwitterEngine which is a great example of how to develop a client that targets a specific API, Twitter. If you know that the serve implements RESTful web services, then you can also take a look at the iPhone on Rails project which implements a generic controller. You provide the model and the controller takes care of the REST.
这篇关于创建一个JSON解析器/网络对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!