English 中文(简体)
Formats for communicating between backend and Objective-C/Cocoa
原标题:

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].

问题回答

PList is a good answer and very usable, but many server side people will be more comfortable producing JSON - TouchJSON is a very good JSON parser for the iPhone.

While there is a plist gem for ruby, JSON or (raw) XML are much more popular outside the Apple world. For instance most JavaScript libraries are set up to speak one or both of these.

So if you re exclusively talking to an iPhone, the plist is probably a good choice, but otherwise you should consider using JSON (or XML).





相关问题
Custom Formating a DateTimePicker using CultureInfo

I am using the DateTimePicker control in a Vb.Net Windows project. I would like the date to reflect the Regional Settings on the user s computer, but also to show the month name, rather than the ...

What settings storage format to choose?

I m writing a Qt application and will need to store the settings for the program. I want them to be easily editable by non-advanced users yet be flexible enough for advanced users (thus allow easy ...

Parsing date with timezone from an email?

I am trying to retrieve date from an email. At first it s easy: message = email.parser.Parser().parse(file) date = message[ Date ] print date and I receive: Mon, 16 Nov 2009 13:32:02 +0100 But I ...

Arduino String Formatting Issue

I m making an Arduino-powered clock, and in the process, I m trying to format integers into two-digit formatted strings for the time read-out (e.g. 1 into "01"). The following gives me "error: ...

How to get fields from such a string?

I m importing some data from a database. The data has been stored by a CMS written in php where I have no control. Here is the data (a dense report from a paypal response): a:56:{ s:8:"business";s:19:...

Nginx raises 404 when using format => js

I upload images to my App using Ajax and an Iframe. In Development everything works like a charm. But in production Nginx suddenly raises a 404 error. When I look into the log, the request never hits ...

Check if string is of SortableDateTimePattern format

Is there any way I can easily check if a string conforms to the SortableDateTimePattern ("s"), or do I need to write a regular expression? I ve got a form where users can input a copyright date (as a ...

热门标签