Jquery中Json对象转为string字符串
使用JSON.stringify,把Json对象转为string字符串,
复杂的嵌套对象也可以转换哦(下面的测试demo是复杂对象的转换)
注:嵌套对象,将转换为嵌套json
<!DOCTYPE html >
<html>
<head>
<title>Json对象转为string字符串-yunjson.com</title>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script>
/*
使用JSON.stringify,把Json对象转为string字符串,复杂的嵌套对象也可以转换哦(下面的测试demo是复杂对象的转换)
*/
</script>
</head>
<body>
<script type="text/javascript">
var JsonItem = new Object();
JsonItem.Name = "Json在线解析";
JsonItem.ProUrl = "www.yunjson.com";
JsonItem.SiteID = 1472222;
JsonItem.SiteLink = "官方QQ群:308250404";
JsonItem.SiteInfo = "Json在线工具(http://www.yunjson.com),Json学习资料专题模块,只为你提供最好的Json学习资料,感谢你的支持";
var SiteList = new Object();
SiteList.Name = "Json在线解析";
SiteList.ProUrl = "www.yunjson.com";
SiteList.SiteLink = "官方QQ群:308250404";
JsonItem.SiteList = SiteList; //嵌套对象,将转换为嵌套json
var JsonItemStr = JSON.stringify(JsonItem);
console.log("Json对象转为string字符串,处理结果如下");
console.log(JsonItemStr);
</script>
</body>
</html>