When to prefer JSON over XML?

后端 未结 19 1411
无人共我
无人共我 2020-11-28 00:31

My requirement is just to display a set of values retrieved from database on a spread. I am using jquery.

相关标签:
19条回答
  • 2020-11-28 01:07

    JSON is the native encoding for javascript. It should be much faster and easier to work with.

    0 讨论(0)
  • 2020-11-28 01:08

    I use JSON unless I'm required to use XML. It's simpler to understand, and (because it requires less configuration overhead) it's easier to program for reading and writing if the libraries are available in your context, and they're pretty ubiquitous now.

    When Amazon first exposed their catalogs as a web service, they offered both JSON and XML. Something like 90% of the implementers chose JSON.

    0 讨论(0)
  • 2020-11-28 01:08

    I am seeing a bit of bias dogma here. It appears that answers for this are over simplified for xml and coming from the context of Web Development only (which makes sense for the question), so I figured id offer some additional insight just in case some one crosses this and needs an answer for data serialization in other contexts.

    Here are the hard and fast rules:

    XML is definitely, not arguably, more powerful. So use it when your data model is complicated enough to need the following features:

    1. Support for Namespaces
    2. Support for Object Orientation ie inheritance/polymorphism
    3. Support for inclusion and extensibility for complex type reuse.
    4. Support needed for a reliable, mature and complete Schema Validation system.
      • the w3c Schema Validation system is vastly more capable to JSON Schema and has more literature to learn it.
    5. Support for mixed content document data modelling up AND record like data modelling.

    JSON is simpler to learn, understand and use. So use it when you dont have time to learn XML and dont have a need for any of the above features. Its also more lightweight on the wire, if that matters for your use case.

    TL:DR, XML can do everything json can do, but is heavier. The reverse is simply not true. Yes Json is simpler and therefor used more, but that does not mean it can supplant XML. In the case I was up against this year, 2020, json didnt make the cut for our use case, we literally needed XML. I can talk about that more if needed. Cheers and good luck.

    0 讨论(0)
  • 2020-11-28 01:09

    I use JSON for any kind of configuration, data interchange or messaging. I use XML only if I have to for other reasons or to semantically mark up document-like data.

    0 讨论(0)
  • 2020-11-28 01:12

    Most newer web technologies work using JSON, so definitively a good reason for using JSON. A great advantage is that in XML you can represent in multiple different ways the same information, which in JSON is more straightforward.

    Also JSON IMHO is much clearer than XML, which makes it for me a clear advantage. And if you are working with .NET, Json.NET is a clear winner to help you work with JSON.

    0 讨论(0)
  • I'd choose XML over JSON if I need to validate the chunk of incoming data, because XML nativly supports this through XSD.

    0 讨论(0)
提交回复
热议问题