Parsing JSON vs parsing XML in iOS

北城以北 提交于 2019-12-13 15:06:51

问题


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.


回答1:


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.




回答2:


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.




回答3:


THis is a useful post that might help you decide.



来源:https://stackoverflow.com/questions/11971487/parsing-json-vs-parsing-xml-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!