3

Scenario :

I am working on a parser for data which is sent back from a server after making a request. The format of data is either JSON or XML.

Question:

  1. Are there any reasons to choose one of these formats over the other one?
  2. Which one is faster, parsing json or parsing xml?

Thanks all.

dda
  • 6,030
  • 2
  • 25
  • 34
tranvutuan
  • 6,089
  • 8
  • 47
  • 83
  • 1
    You may find your answer here: http://stackoverflow.com/questions/3152700/what-type-of-webservice-works-best-with-ios – Aniruddh Aug 15 '12 at 14:48

3 Answers3

3

When JSON is preferred it is usually because it is significantly shorter. That saves transmission traffic and therefore time and battery power (not a bad thing, though?). Meaning: Even if parsing JSON would be slower (which I doubt), the gain during the tranfer over the air would certainly compensate any additional CPU time during parsing.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71
2

Checkout this tutorial about parsing XMLs. I might sound opinionated, but if there's a choice go for JSON, although I have no clue what situation your project is in. I would certainly look at the entire architecture (trade-offs and choices) of the project before making a decision. From my experience, understanding JSON and relating it to NSDictionaries and NSArrays is much easier than understanding XMLs.

Ravi
  • 7,929
  • 6
  • 38
  • 48
1

THis is a useful post that might help you decide.

petert
  • 6,672
  • 3
  • 38
  • 46