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 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题