1.json字符串------>json对象
- js中使用JSON.parse()函数
var jsonStr = '{"name":"郑科","age":23}';
var json = JSON.parse(jsonStr);
console.log(json);//输出:Object {name: "郑科", age: 23}
- js中使用eval()函数
var jsonStr = '{"name":"郑科","age":23}';
var json = eval(jsonStr);
console.log(json);//输出:Object {name: "郑科", age: 23}
- jQuery中使用jQuery.parseJSON()
var jsonStr = '{"name":"郑科","age":23}';
var json = jQuery.parseJSON(jsonStr);
console.log(json);//输出:Object {name: "郑科", age: 23}
2.Json对象------>json字符串
- 使用JSON.stringify()
var jsonStr = '{name:"郑科",age:23}';
var json = JSON.stringify(json);
console.log(json);//输出:Object {"name": "郑科", "age": 23}