如何通过HTTP POST发送填充了对象的NSArray? [英] How would I send an NSArray filled with objects over a HTTP POST?

查看:164
本文介绍了如何通过HTTP POST发送填充了对象的NSArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPhone端有一个产品/购物清单(包含名称,product_id等的产品对象)。我希望将此列表发送到服务器,我将服务器上的列表与iphone中的列表进行比较(合并所做的更改并将合并列表发送回iphone)。

I have a product/shopping list (consisting of product objects with a name, product_id etc) on the iPhone side. I wish to send this list to the server where I will compare the list on the server with the one from the iphone (to merge the changes made and send the merged list back to the iphone).

我如何通过HTTP POST将我的阵列发送到服务器?我知道你可能不能只发送
数组,你可能要把它存储在xml或者json中。但是我仍然想在开始编码之前有
有一些可能性:)

How would I send my array over a HTTP POST to the server? I know you probably can't just send the array, you would have to store it in either xml or json probably.. But still I'd like to have some possibilities before I start coding :)

提前致谢,

LeWiOn

编辑:解决了:)感谢帮助人员!

Edit: Solved :) Thanks for the help guys!

答案 http://andyj.be.s79833.gridserver.com/blog/?p=65

推荐答案

Json似乎是你最好的选择。 Xml很重,解析起来更复杂。 SBJson库在序列化对象图方面做得非常出色。我已经做了这种过程但从不尝试将我的数组发送到服务器,相反,我比较了服务器和本地的散列,并在需要时下载了新版本。

Json seems to be your best option. Xml is heavy and more complex to parse. SBJson library makes an excellent work at serializing object graph. I already made this kind of process but never try sending my array to the server, instead, I compared hash of both server and local and downloaded the new version if needed.

祝你好运。

编辑
使用SBJSON库,创建对象的json表示形式如下:

Edit Using SBJSON Library, creating the json representation of an object is made like :

[myObject JSONRepresentation]

SBJSON Library可以在这里找到

SBJSON Library can be found here

编辑:
Json本质上是数组或字典的表示。如果你的对象就是其中之一,那么一切都会正常运行,如果没有,你必须在对象中实现proxyForJson方法才能序列化它。此方法应返回一个字典,其键是属性名称,值是属性值。

Edit : Json is by nature a representation of an array or a dictionnary. If your object is one of those, everything will run fine, if not, you have to implement the proxyForJson method in your object in order to serialize it. This method should returns a dictionary whose keys are properties names and value are properties values.

这篇关于如何通过HTTP POST发送填充了对象的NSArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆