常用json间字符串与json对象的转化
1.JSON对象转化问字符串var obj = {name : "Geoff Lui",age : 26};
console.log(obj); var jsonstr = JSON.stringify(obj); console.log(jsonstr);//返回结果 '{"name":"Geoff Lui","age":26}'2.JSON 字符串转化为 json对象格式
var jsonStrs = '{"name":"zhangsan","age":23,"email":"chentging@aliyun.com"}';console.log(jsonStrs)var json = JSON.parse(jsonStrs);console.log(json);//输出:Object {name: "zhangsan", age: 23, email: "chentging@aliyun.com"}
3.把数据在前后端之间传递,需要把json对象转换为json字符串 JSON.stringify({"字段":参数,.....,"字段":参数n});