iPhone -- server交互数据格式

iPhone开发可以参考以下:

http://www.cocoachina.com/iphonedev/index.html

http://www.apple.com.cn/developer/iphone/

 

iPhone的应用程序,开发者上传到appstore,分为收费跟免费两种。

iPhone的所有者可以从appstore下载程序使用。呵呵,不少收费application的开发者都成了百万富翁哦。

 

下面要讨论的是:C/S模式的应用程序。

iPhone的application应用程序日趋强大,以至于大多数的程序都不局限于独立运行在iPhone上,它们需要联机,需要从server获取数据,需要利用server存储信息。

 

我在项目中的做法:

iPhone app端利用Get或者POST向server发送请求。

小量数据用Get,表格之类用Post。用户信息相关https,server相应加上非https勿入。

 

关键在于server!从request请求中取得参数,处理完毕,怎么样返回给iPhone app。

XML! 对。

server把返回值依照相约格式生产XML。

iPhone app通过解析XML得到返回值。

 

e.g.

<dict>
<key>Name</key>
<string>John Doe</string>
<key>Phones</key>
<array>
<string>408-974-0000</string>
<string>503-333-5555</string>
</array>
</dict>

 

dict表示范围

key表示变量名

 

第一个变量Name, String型的,值为John Doe

第二个变量Phones,String型的数组

 

code:

使用dom4j

        Document document = DocumentHelper.createDocument();
        Element dictElement = document.addElement("dict");

 

            Element arrayElement = dictElement.addElement("array");
            List<BusinessVO> businessList = otherService.getBuildingBusinessList(buildingId, Integer.parseInt(verifyStatus));
            for(BusinessVO business : businessList){
                Element businessElement = arrayElement.addElement("business");
                Element retElement = businessElement.addElement("key");
                retElement.setText("businessId");
                Element retValue = businessElement.addElement("String");
                retValue.setText(business.getId());
               
                Element retElement1 = businessElement.addElement("key");
                retElement1.setText("businessName");
                Element retValue1 = businessElement.addElement("String");
                retValue1.setText(business.getBuildingName());

………………

省略n行

 

结果为:

<dict>

<array>

<business>
<key>businessId</key>
<String>100022796</String>
<key>businessName</key>
<String>1 Leroy St</String>
<key>businessContent</key>
<String/>
<key>phoneNumber</key>
<String>(646) 666-4835</String>
<key>address</key>
<String>1 Leroy St</String>
<key>website</key>
<String/>
<key>category</key>
<int>0</int>
<key>refBusinessId</key>
<String>0</String>
<key>agreeCount</key>
<int>0</int>
<key>disagreeCount</key>
<int>0</int>
<key>relocatedListCount</key>
<int>0</int>
<key>notedListCount</key>
<int>0</int>
<key>userId</key>
<String>0</String>
<key>centerX</key>
<int>49822</int>
<key>centerY</key>
<int>23253</int>
</business>

<business>
<key>businessId</key>
<String>100022797</String>
<key>businessName</key>
<String>1 Leroy St</String>
<key>businessContent</key>
<String/>
<key>phoneNumber</key>
<String>(212) 242-3728</String>
<key>address</key>
<String>1 Leroy St</String>
<key>website</key>
<String/>
<key>category</key>
<int>0</int>
<key>refBusinessId</key>
<String>0</String>
<key>agreeCount</key>
<int>0</int>
<key>disagreeCount</key>
<int>0</int>
<key>relocatedListCount</key>
<int>0</int>
<key>notedListCount</key>
<int>0</int>
<key>userId</key>
<String>0</String>
<key>centerX</key>
<int>49822</int>
<key>centerY</key>
<int>23253</int>
</business>

</array>
</dict>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值