<!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>

 

posted on 2015-05-20 17:33  高尔础础  阅读(197)  评论(1编辑  收藏  举报