上QQ阅读APP看书,第一时间看更新
XML and JSON
Both XML and JSON are used by web services to represent structured sets of data or objects.
As discussed in previous sections, XML uses a syntax based on tags and properties, and values for those tags; for example, the File menu of an application, can be represented as follows:
<menu id="m_file" value="File"> <popup> <item value="New" onclick="CreateDocument()" /> <item value="Open" onclick="OpenDocument()" /> <item value="Close" onclick="CloseDocument()" /> </popup> </menu>
JSON, on the contrary, uses a more economic syntax resembling that of C and Java programming languages. The same menu in JSON format will be as follows:
{"menu": { "id": "m_file", "value": "File", "popup": { "item": [ {"value": "New", "onclick": "NewDocument()"}, {"value": "Open", "onclick": "OpenDocument()"}, {"value": "Close", "onclick": "CloseDocument()"} ] } }}