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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失