Common data exchange format

First, what is a data interchange format

Among different programs, computers, or between different programming languages ​​for data exchange, but also a need for an understanding that everyone can hear 'language', which is the data exchange format, it is to describe the data in a specific format via text .

Second, several common data exchange format

Client common data exchange format xml, json, yaml.

1、JSON(JavaScript Object Notation)


{
  "dates": {
    "date": [
      {
        "id": "1",
        "name": "JSON",
        "abb": "JavaScript Object Notation"
      },
      {
        "id": "2",
        "name": "XML",
        "abb": "eXtensible Markup Language"
      },
      {
        "id": "3",
        "name": "YAML",
        "abb": "Yet Another Markup Language"
      }
    ]
  }

 JSON is a lightweight data interchange format text, and JavaScript code creates an object identical in syntax, the key | composed | (key value) value.

JSON format:

a: Data in the name | value pairs

b. data separated by commas

c. braces save the object

d. brackets backup array

JSON advantages:

a. self descriptive, easy to read write, but also easy to generate and parse the machine

b. Use Javascript syntax to describe data objects, but JSON is still independent of language and platform. JSON parser and JSON library supports many different programming languages. Currently a lot of dynamic (PHP, JSP, .NET) programming languages ​​support JSON

c. ideal for server interaction with JavaScript

Use JSON:

a. JSON string read

b. Processing string eval () or parse ()

2.XML(eXtensible Markup Language)


<?xml version="1.0" encoding="UTF-8" ?>
<dates>
    <date>
        <id>1</id>
        <name>JSON</name>
        <abb>JavaScript Object Notation</abb>
    </date>
    <date>
        <id>2</id>
        <name>XML</name>
        <abb>eXtensible Markup Language</abb>
    </date>
    <date>
        <id>3</id>
        <name>YAML</name>
        <abb>Yet Another Markup Language</abb>
    </date>
</dates>

Extensible Markup Language, a subset of the Standard Generalized Markup Language, is a method for marking an electronic document to have a structured markup language.

XML format:

a statement: Defining XML file version and character set

. B root tag: the root node of the tree structure

c sub-elements: the terms of a relative, can be customized, must have an end tag, case sensitive

d property: An element can have different attributes multiple names

Working XML:

a. read XML documents

b. Using XML DOM traverse the document circulation

c. reading and storing the variable value

3、YAML(Yet Another Markup Language)

dates: 
 date: 
  - 
   id: 1
   name: JSON
   abb: "JavaScript Object Notation"
  - 
   id: 2
   name: XML
   abb: "eXtensible Markup Language"
  - 
   id: 3
   name: YAML
   abb: "Yet Another Markup Language"

YAML is an intuitive format data sequence capable of being recognized by the computer

YAML format:

a. the structure represented by indenting

. B continuous project by a '-' indicates

c.key | value with ':' delimited

YAML scope of application:

a. Due to simple, low cost analytical, particularly suitable for use in a scripting language

b.YAML more suitable for serialization. Host because it is a direct transfer of data types.

c.YAML do configuration file is also good. For example, Ruby on Rails configuration on the selection of YAML.

YAML question:

Due to compatibility issues, transfer of data between different languages, it is recommended not to use YAML

There is an expression CSV (comma delimited), and use the table to represent the delimiter format of the data, we will not pay more in narrative, interested readers can go to find out. In comparison, the three listed herein, JSON and XML used a little more extensive. And from JSON and XML comparison implementation, easy to see, JSON faster and easier to use than XML, JSON respected a little more personal. Of course, the circumstances have specific analysis, rational use of these data exchange format, we will be able to write more excellent, powerful code!

 

 

Published 10 original articles · won praise 4 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_42528204/article/details/81454014