Blogger Information
Blog 56
fans 7
comment 11
visits 222476
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jquery字符串转json与json转字符串方法
樂成的开发笔记
Original
3249 people have browsed it

1. JSON.stringify(jsonobj): 可以将json对象转换成json字符串

2. JSON.parse(jsonstr)  将格式完好的json字符串转为与之对应的json对象


实例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>test</title> 
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  var jsonstr = '{"status":1,"msg":"ok"}';
  var jsonobj = JSON.parse(jsonstr);
  console.log(jsonobj);
  var jsonstring = JSON.stringify(jsonobj);
  console.log(jsonstring);
  alert(jsonstring)

});
</script>
</head>
<body>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post