JSON

JSON

Object

enclosed within braces, { }

– Example: { "name": "html", "years": 5 }

Array

enclosed within brackets, [ ]

– Example:

• [{“name":"Jo","email":"[email protected]"}, {“name":"Jo","email":"[email protected]"}]

JSON syntax

value

A value can be: A string, a number, true, false, null, an object, or an array

– Values can be nested

number

All numbers are decimal--no octal or hexadecimal

JSON & XML

similarity:

– Both are human readable– Both have very simple syntax– Both are hierarchical– Both are language independent– Both can be used by Ajax– Both supported in APIs of many programming languages

difference:

– Syntax is different

– JSON is less verbose #更简洁

– JSON can be parsed by JavaScript’s eval() method #解析用

– JSON includes arrays

– Names in JSON must not be JavaScript reserved words #避开js关键字

– XML can be validated

你可能感兴趣的:(JSON)