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.

    评论

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python