Json的使用

  1. JSON 语法:

  2. 数据在名称/值对中
  3. 数据由逗号分隔
  4. 花括号保存对象
  5. 方括号保存数组
  • var person = {"name":"zhangSan", "age":"18", "sex":"male"};

    alert(person.name + ", " + person.age + ", " + person.sex);

    注意,key也要在双引号中!

    JSON值:

  • 数字(整数或浮点数)
  • 字符串(在双引号中)
  • 逻辑值(true 或 false)
  • 数组(在方括号中)
  • 对象(在花括号中)
  • null

1. jsp使用jason 

Json的使用

var person = {"name":"zhangSan", "age":"18", "sex":"male", "hobby":["cf", "sj", "ddm"][c1] };

alert(person.name + ", " + person.age + ", " + person.sex + ", " + person.hobby);

 

带有方法的JSON对象:

var person = {"name":"zhangSan", "getName":function() {return this.name;}};

alert(person.name);

alert(person.getName());