How does JSON compare to XML in terms of file size and serialisation/deserialisation time?

前端 未结 8 1789
萌比男神i
萌比男神i 2020-12-28 16:43

I have an application that performs a little slow over the internet due to bandwidth reasons. I have enabled GZip which has improved download time by a significant amout, bu

8条回答
  •  隐瞒了意图╮
    2020-12-28 16:52

    
    
    "person":{"firstname":"Fred", 
              "lastname":"Flintstone",  
              "age":38, 
              "spouse":"Wilma" }
    

    XML: 80 chars

    JSON: 92 chars.

    XML is the 13% slimmer winner, who would have thought for all the bogus claims?

    [Example taken from Cheeso above. Note that carriage return types change the size but equally for both. Without any returns in either, the ratio is XML: 74, JSON: 86, a 14% difference]

    Someone claimed in this discussion that "using attributes for content is cheating" (citing [this][1]).

    1) Pray tell how well formed XML is 'cheating'? If it doesn't cheat the (very long) spec, then let's please get over it. Valid is valid.

    2) In that case an ASP.NET web.config is 'cheating', among a thousand other big-dog examples.

    
    

    To be fair, there are those who tend to have a bloated-XML mentality in how they form the XML.

    But it should not be said that the 13% slimmer XML variety is not just as valid. And thus it even beats JSON (in size).

    [1]: http://www.ibm.com/developerworks/xml/library/x-eleatt/index.html [2004 article, mind you]

提交回复
热议问题