douren5490 2009-05-13 05:19
浏览 109

iPhone应用程序:如何从API获取数据,解析和存储以供以后使用?

I'm new to iPhone app development so excuse me if I use the wrong terminology, or ask the wrong questions. Basically, I'm trying to write an App that includes downloading a dataset, saving it for later, and checking if the dataset has been updated, but I don't know where to begin.

When I say dataset, I mean a multi-dimensional array of key/value pairs.

I will be creating a site that my App will pull the data from. I think REST is the technology that it will be using (new to REST, too), being served up by a Zend Framework application, using MySQL as the back end database.

So the data will be stored in a MySQL database, and I need to be able to download chunks, which I assume will be stored in my App's SQLite database, to be accessed later (when internet access is not present). At some point in my application's life cycle, I want to check if the dataset that I have downloaded is the most recent version.

There are a lot of parts to this that I am still confused about. Can anyone please shed some light on any/all of the areas that I have touched upon. Is there any iPhone framework that I should be aware of that would make this process go faster/easier?

Thanks!

Update: Maybe I should break this up to make it easier to answer:

  1. I am assuming that my API will retrieve the data from the database and output the response as XML. Is this the best/only option?
  2. In my App, how can I make an API call?
  3. How can I parse the response (probably XML) from an API call and store it for later retrieval?
  • 写回答

2条回答 默认 最新

  • doushui3216 2009-05-14 16:20
    关注

    If just wanting to fetch (GET) data, a REST API call is simply a URL you go to that usually returns XML instead of HTML. Your URL could be www.site.com/rest/fetchstuff or www.site.com/dosomethigncool, doesn't matter. For the app to "call" the API, it'd connect to that URL and include whatever parameters then download the XML from the server.

    Let's say your app finds cars for sale. The URL/REST API would be www.site.com/rest/cars/findAll. Your app would call this URL: www.site.com/rest/cars/findAll?make=jeep&model=wrangler. The server would search the database for all cars that are Jeep Wranglers then return the results formatted as XML. Your app would download that XML then parse it.

    Check out the SeismicXML sample project. NSURLConnection is what connects to your REST API and downloads the data (XML). NSXMLParser can parse the XML you download.

    评论

报告相同问题?

悬赏问题

  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败