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.
我正在处理一个解析器,用于在发出请求后从服务器发回的数据。数据格式是JSON或XML。
Question:
- Are there any reasons to choose one of these formats over the other one?
- Which one is faster, parsing json or parsing xml?
有没有理由选择其中一种格式?
哪一个更快,解析json或解析xml?
Thanks all.
3 个解决方案
#1
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.
查看本教程有关解析XML的信息。我可能听起来很自以为是,但如果可以选择JSON,虽然我不知道你的项目是什么情况。在做出决定之前,我肯定会关注项目的整个架构(权衡和选择)。根据我的经验,理解JSON并将其与NSDictionaries和NSArrays相关联比理解XML要容易得多。
#2
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.
当JSON是首选时,通常是因为它明显更短。这样可以节省传输流量,从而节省时间和电池电量(但不是坏事吗?)。含义:即使解析JSON会更慢(我怀疑),通过空中传输期间的增益肯定会在解析过程中补偿任何额外的CPU时间。
#1
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.
查看本教程有关解析XML的信息。我可能听起来很自以为是,但如果可以选择JSON,虽然我不知道你的项目是什么情况。在做出决定之前,我肯定会关注项目的整个架构(权衡和选择)。根据我的经验,理解JSON并将其与NSDictionaries和NSArrays相关联比理解XML要容易得多。
#2
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.
当JSON是首选时,通常是因为它明显更短。这样可以节省传输流量,从而节省时间和电池电量(但不是坏事吗?)。含义:即使解析JSON会更慢(我怀疑),通过空中传输期间的增益肯定会在解析过程中补偿任何额外的CPU时间。