后端和Objective-C / Cocoa之间的通信格式 [英] Formats for communicating between backend and Objective-C/Cocoa

查看:203
本文介绍了后端和Objective-C / Cocoa之间的通信格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个连接到后端服务器的iPhone应用程序。它需要通过几次请求与它进行多次通信。我发送HTTP消息,但我想要接收更复杂的响应,我可以解析不知何故。据推测,我可以提供任何类型的格式从服务器的响应,所以我的问题是:哪一个会更容易(可能更快)使用/解析Objective-C / Cocoa,并在某种类型的字典中转换?



我知道这有点主观,但我仍然认为这是一个有效的问题,一些编程语言只是更多的支持一些格式,而对别人较少。

$从Cocoa的角度来看,最简单的格式是一个

文档/ Cocoa / Conceptual / PropertyLists / Introduction / Introduction.htmlrel =nofollow noreferrer>属性列表,因为Cocoa可以将它原生地解析为字典或数组。



您可以使用NSDictionary的 + dictionaryWithContentsOfFile: + dictionaryWithContentsOfUrl:将plist文件读入字典。



如果您的plist数据不在文件中,您还可以将包含plist数据的NSData对象转换为字典 + [NSPropertyListSerialization dataFromPropertyList :format:errorDescription:] 或使用 - [NSString propertyList] 将NSString转换为字典。


I'm developing an iPhone app that is connected to a backend server. It needs to communicate with it many times, through several requests. I'm sending HTTP messages, but I want to receive more complex responses that I can parse somehow. Supposedly, I can provide any type of format for responses from the server, so my question is: which one would be easier(maybe even faster) to use/parse for Objective-C/Cocoa, and transform in a dictionary of some kind?

I know it's a bit subjective but I still think it's a valid question, some programming languages just have more support for some formats and less for others.

解决方案

From Cocoa 's perspective, the simplest format is a property list as Cocoa can parse this natively into a dictionary or an array.

You can use NSDictionary's +dictionaryWithContentsOfFile: and +dictionaryWithContentsOfUrl: to read a plist file into a dictionary.

If your plist data is not in a file, you can also convert an NSData object containing plist data to a dictionary with +[NSPropertyListSerialization dataFromPropertyList:format:errorDescription:] or convert an NSString to a dictionary with -[NSString propertyList].

这篇关于后端和Objective-C / Cocoa之间的通信格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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