json学习

1.定义

json是一种轻量级的数据交换格式,基于javascript的一个子集,json采用完全独立语言的文本格式,但使用类似于c语言家族的习惯,使json成为理想的数据交换语言,易于阅读和编写同时易于机器的解析和生成。

2.赋值给变量

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": "science fiction" },
{ "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
{ "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" }
],
"musicians": [
{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
{ "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }
] }
3.取值
people.musicians[1].lastName 的值为  Rachmaninoff
4.赋值
people.musicians[1].lastName = "高艳龙"
5.换回 字符串
string myJson = people.toJsonString();
6.校验工具推荐:BeJson

你可能感兴趣的:(json)