简体   繁体   English

如何通过HTTP POST发送充满对象的NSArray?

[英]How would I send an NSArray filled with objects over a HTTP POST?

I have a product/shopping list (consisting of product objects with a name, product_id etc) on the iPhone side. 我在iPhone端有一个产品/购物清单(包含名称,product_id等产品对象)。 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). 我希望将此列表发送到服务器,在这里我将服务器上的列表与iphone上的列表进行比较(合并所做的更改并将合并后的列表发送回iphone)。

How would I send my array over a HTTP POST to the server? 我如何通过HTTP POST将阵列发送到服务器? 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 :) 我知道您可能不能只发送数组,您可能必须将其存储在xml或json中。但是在我开始编码之前,我仍然想拥有一些可能性:)

Thanks in advance, 提前致谢,

LeWiOn LeWiOn

Edit : Solved :) Thanks for the help guys! 编辑 :解决:)感谢您的帮助!

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

Json seems to be your best option. 杰森似乎是您最好的选择。 Xml is heavy and more complex to parse. Xml很重,解析起来也比较复杂。 SBJson library makes an excellent work at serializing object graph. SBJson库在序列化对象图方面做得很好。 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. 我已经进行了这种处理,但从未尝试将数组发送到服务器,而是比较了服务器和本地的哈希值,并在需要时下载了新版本。

Good luck. 祝好运。

Edit Using SBJSON Library, creating the json representation of an object is made like : 使用SBJSON库进行编辑 ,创建对象的json表示形式如下:

[myObject JSONRepresentation]

SBJSON Library can be found here SBJSON库可以在这里找到

Edit : Json is by nature a representation of an array or a dictionnary. 编辑: Json本质上是数组或字典的表示。 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. 如果您的对象是其中之一,那么一切都会正常运行,否则,您必须在对象中实现proxyForJson方法以对其进行序列化。 This method should returns a dictionary whose keys are properties names and value are properties values. 此方法应返回一个字典,其键是属性名称,而value是属性值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM