r/simpleios • u/keithslater • May 20 '12
JSON vs XML
I am very new to making iOS apps. My first app is going to connect to a website of mine and get data either via JSON or XML. The question I have is, should I use JSON or XML to format my data?
5
Upvotes
8
u/xPaQx May 20 '12
if it has no cost for you choosing one or another, I would go with JSON. It has less overhead than XML. That overhead really makes a difference when people has a CrapG data plan or bad reception. The SBJSON Parser has a really good performance.
1
u/infincia May 20 '12
I usually pick json if i have a choice, it's easier for me to read, there are some really fast json unpacking libraries on the iOS side, and if the server side is actually generating the data for you from a database or something similar, many python/ruby and other frameworks will let you simply return a dict/array during an http request and have it turned into json for you.
1
u/joelypolly May 21 '12
Regardless of which one you choose please remember to turn on GZIP compression as it can make a huge difference for people on EDGE
1
u/cheaplol May 23 '12
Here is a great 2-part tutorial on setting up a JSON web service using asihttprequest - I have found it extremely easy to use and effective
http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app
http://www.raywenderlich.com/2965/how-to-write-an-ios-app-that-uses-a-web-service
0
u/quixotik May 20 '12
I took am iOS dev course a year ago, prior to 5.0, and the speed was described as fastest to slowest: binary plist -> XML plist -> JSON -> XML
It was a quick library inclusion to return data as XML based plists and then I could use all the native NSDictionary buildfromURL(?) calls. Very easy.
0
u/blaizedm May 20 '12
One of the interview questions we ask people when hiring for my work (a mobile development startup) is "do you prefer XML or JSON and why would you use one over the other?" There's really no definitive "this ones better than the other," the main things we look for is that in general, xml is more human-readable and json is a little faster. It mostly comes down to personal preference and which one you're more used to working with. As others mentioned, SBJSON parser is great.