`
flyfoxs
  • 浏览: 294540 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

JavaScript JSON 与 String 互转

阅读更多

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> JSON 测试 </title>

  <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"> </script>
 </head>

 <body>
  
  <script> 
	//建立一个简单的Json对象
	var testJsonObj = {"name":"lilao", "email":"xx@qq.com"};	
	alert("JSON OBJ:" + testJsonObj);

	//讲Json对象直接转换成字符串
	var testJsonString = JSON.stringify(testJsonObj);
	alert("JSON String:"+ testJsonString); 

	
	//将字符串转换成Json对象,使用了Jquery函数
	alert(jQuery.parseJSON(testJsonString));
	alert(jQuery.parseJSON(testJsonString).name);  
  </script>
 </body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics