doutiaoku4495 2010-12-12 21:49
浏览 26
已采纳

从PHP获取数据到iOS应用程序的最佳方法是什么?

What is the best way to get data from the internet, compressed and composed by PHP, to an iOS app? Currently, the app reads a string formatted like this:

category1#object2#object3#object4~category2#object2#object3[…]

And that is split up by the #'s and ~'s.

Is there a better way to do this, both in the way the data is retrieved (the site it gets it from is open for everyone), and the way the data is formatted?

  • 写回答

3条回答 默认 最新

  • dpf25323 2010-12-12 21:52
    关注

    Use JSON:

    {"category1":["object1", "object2", "object3", "object4"], "category2":["object1", "object2"]}
    

    So say you had a PHP object or associative array, you'd be able to simply invoke json_encode on it and be done with it.

    On the iOS end, you'd want to use JSONKit to parse it.

    The best thing about these two ends of the pipeline is that there is native support for them. For example, json_encode can encode any PHP object to a readable JSON string, while JSONKit can parse a JSON object and store it in an NSDictionary or NSArray.

    Heck, with JSONKit, it augments the capability (using categories on NSDictionary and NSArray) to convert NSDictionary and NSArray objects into JSON, so you can even have a two-way JSON communication pipeline.

    (We do this with our games at Freeverse, the methodology is tried and tested.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里