Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON or SOAP (XML)?

I'm developing a new application for the company. The application have to exchange data from and to iPhone.

Company server side uses .NET framework.

For example: the class "Customer" (Name, Address etc..) for a specific CustomerNumber should be first downloaded from server to iphone, stored locally and then uploaded back to apply changes (and make them available to other people). Concurrency should not be a problem (at least at this time...)

In any case I have to develop both the server side (webservice or whatever) and the iPhone app.

I'm free to identify the best way to do that (this is the application "number ONE" so it will become the "standard" for the future).

So, what do you suggest me ?

Use SOAP web services (XML parsing etc..) or user JSON ? (it seems lighter...) Is it clear to me how to "upload" data using SOAP (very long to code the xml soap envelope ... I would avoid) but how can I do the same using JSON ?

The application needs to use date values (for example: last_visit_date etc..) what about date in Json ?

like image 859
Fulkron Avatar asked Aug 06 '09 08:08

Fulkron


People also ask

What is JSON and SOAP?

The content of a SOAP message is XML data, whereas a JSON message contains JSON data. JSON and XML are different encoding mechanisms for describing structured data. JSON tends to be a more efficient encoding mechanism, so a typical JSON message will be smaller than the equivalent XML message.

What is JSON and XML?

JSON is a data interchange format and only provides a data encoding specification. XML is a language to specify custom markup languages, and provides a lot more than data interchange. With its strict semantics, XML defined a standard to assert data integrity of XML documents, of any XML sub-language.


2 Answers

JSON has several advantages over XML. Its a lot smaller and less bloated, so you will be passing much less data over the network - which in the case of a mobile device will make a considerable difference.

Its also easier to use in javascript code as you can simply pass the data packet directly into a javascript array without any parsing, extracting and converting, so it is much less CPU intensive too.

To code with it, instead of an XML library, you will want a JSON library. Dates are handled as you would with XML - encode them to a standard, then let the library recognise them. (eg here's a library with a sample with dates in it)

Here's a primer.

like image 105
gbjbaanb Avatar answered Sep 30 '22 02:09

gbjbaanb


Ah, the big question: JSON or XML?

In general, I would prefer XML only when I need to pass around a lot of text, since XML excels at wrapping and marking up text.

When passing around small data objects, where the only strings are small (ids, dates, etc.), I would tend to use JSON, as it is smaller, easier to parse, and more readable.

Also, note that even if you choose XML, that does not by any means mean you need to use SOAP. SOAP is a very heavy-weight protocol, designed for interoperability between partners. As you control both the client and server here, it doesn't necessarily make sense.

like image 40
Avi Avatar answered Sep 30 '22 03:09

Avi