JSON

2019-05-05  本文已影响0人  CHENpq

JSON

Object

enclosed within braces, { }

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

Array

enclosed within brackets, [ ]

– Example:

• [{“name":"Jo","email":"a@b.com"}, {“name":"Jo","email":"a@b.com"}]

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

上一篇 下一篇

猜你喜欢

热点阅读