js:JSON.parse(String xx)将字符串转为json
JsonObject(单个对象) ,JsonArray(数组),fromObject()
json中对象:对象的属性和值是键值对形式,多个属性之间用","隔开,键一定要使用""包起来,值是数字可以不用带""
属性可以是一个对象
{
"id":3,
"address":{
"city":"深圳",
"country":"china"
}
}
json中数组:
[
{
"id":3,
"address":{
"city":"深圳",
"country":"china"
}
},{
"id":"4",
"name":"ssg"
}
]
JavaScript 函数 eval() 可用于将 JSON 文本转换为 JavaScript 对象
var txt = '{ "employees" : [' +
'{ "firstName":"Bill" , "lastName":"Gates" },' +
'{ "firstName":"George" , "lastName":"Bush" },' +
'{ "firstName":"Thomas" , "lastName":"Carter" } ]}';
var obj = eval ("(" + txt + ")");
JsonObject(单个对象) ,JsonArray(数组),fromObject()
json中对象:对象的属性和值是键值对形式,多个属性之间用","隔开,键一定要使用""包起来,值是数字可以不用带""
属性可以是一个对象
{
"id":3,
"address":{
"city":"深圳",
"country":"china"
}
}
json中数组:
[
{
"id":3,
"address":{
"city":"深圳",
"country":"china"
}
},{
"id":"4",
"name":"ssg"
}
]
JavaScript 函数 eval() 可用于将 JSON 文本转换为 JavaScript 对象
var txt = '{ "employees" : [' +
'{ "firstName":"Bill" , "lastName":"Gates" },' +
'{ "firstName":"George" , "lastName":"Bush" },' +
'{ "firstName":"Thomas" , "lastName":"Carter" } ]}';
var obj = eval ("(" + txt + ")");