http://baike.baidu.com/view/136475.htm?fr=aladdin
http://www.w3school.com.cn/json/json_intro.asp
JSON 类似XML 采用结构化的方式存储数据
JSON语法规则
- 采用名称/值存储数据
- 数据由逗号(',')分隔
- 花括号('{}')中存储对象
- 方括号('[]')存储对象的数组
JSON中存储值得类型
- 数值
- 逻辑值(false/true)
- 字符串
- 对象
- null
实例
var people={"programmers":[{"firstName":"Brett","lastName":"McLaughlin","email":"aaaa"},
{"firstName":"Jason","lastName":"Hunter","email":"bbbb"},
{"firstName":"Elliotte","lastName":"Harold","email":"cccc"}
],
"authors":[
{"firstName":"Isaac","lastName":"Asimov","genre":"sciencefiction"},
{"firstName":"Tad","lastName":"Williams","genre":"fantasy"},
{"firstName":"Frank","lastName":"Peretti","genre":"christianfiction"}
],
"musicians":[
{"firstName":"Eric","lastName":"Clapton","instrument":"guitar"},
{"firstName":"Sergei","lastName":"Rachmaninoff","instrument":"piano"}
]}
数据访问
people.authors[1].genre//Valueis"fantasy"
people.musicians[3].lastName//Undefined.Thisreferstothefourthentry,andthereisn'tone
people.programmers[2].firstName//Valueis"Elliotte"
数据赋值
people.authors[1].genre=“new value”;
主要用途
web前后台的数据传输
php 中可通过echo 将JSON数据传递到前端
PHP 处理JSON数据的函数有json_encode()和json_decode() .
JavaScrip对JSON数据解码函数为eval(),格式 eval('('+JSON+')');
以上函数对应着 数组 数据到前后台的传输.