<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="智能社 - zhinengshe.com" /> <meta name="copyright" content="智能社 - zhinengshe.com" /> <title>智能社 - www.zhinengshe.com</title> <script> var strJson = '{"username":"zns","pwd":123456,"age":18}';//标准格式的json:属性名必须是双引号 // var strJson = "{'username':'zns','pwd':123456,'age':18}"; // 1、eval 转为object var json = eval("("+strJson+")");//转为json
//2.JSON.parse(strJSON) 兼容ie8+
var json = JSON.parse(strJSON);
console.log(typeof json) //object
var strJson = JSON.stringify(json);//json转为字符串 console.log(strJson) //{"username":"zns","pwd":123456,"age":18} console.log(typeof strJson) //string </script> </head> <body> </body> </html>