Json(JavaScript Object Notation)对象表示标识,是一种轻量级的数据交换语言,比XML更容易解析,独立于语言和平台。
语法规则:
对象用{}保存
数据用键值对保存
数据间由逗号分隔
数组用[]保存
如下所示:
{"id":1,"name":"john","arr":[1,2,3],"o":{"id":101,"name":"name101","isFine":true,"isHave":null},"age":18}
支持数据类型:
数字,字符串,布尔值,数组,对象,null
{"name":"john","id":1,"istrue":true;"arr":[1,2,3],"o":{"id":101,"name":"name101","isFine":true,"isHave":null},"empty":null}
声明及取值:
$(function(){
var str = ‘{"id":1,"name":"john","arr":[1,2,3],"o":{"id":101,"name":"name101","isFine":true,"isHave":null},"age":18}‘;
var obj = $.parseJSON(str);
console.log("age ="+obj.age);
console.log("name = " + obj.o.name);
});
console:
18
name101
时间: 2024-10-11 01:31:25