一、JSON对象中有两个非常好用的方法:
1 JSON.stringify接收一个JS对象转化为json字符串
2 JSON.parse接受json字符串转化为JS对象
const my={
name:"dylan",
age:"18"
}
let myObj=JSON.stringify(my)
console.log(myObj)//"{"name":"dylan","age":"18"}"
let myStr=JSON.parse(myObj)
console.log(myStr);//{name: "dylan", age: "18"}
注:JSON对象与普通对象的区别是JSON对象键值对都必须用双引号
https://www.cnblogs.com/my466879168/p/12444040.html
二、将字符串转换为json对象
JSON.parse('[{"t":"a","v":"b,s,g"},{"t":"c","v":"d,h,e"}]');
https://www.cnblogs.com/taiyonghai/p/5663541.html
https://my.oschina.net/jast90/blog/386820
三、将json对象转为json字符串
使用JSON.stringify()
<script type="text/javascript">
/*
* 请在下面编写JS代码
*/
function report() {
var ids = _xtable_CheckedCheckboxId();
if (ids == '') {
alert("请选择上报数据!");
return;
}
$.ajax({
url: '/jlkf/szyd/sxqd.jsp',
type: 'post',
data: { 'ids': ids },
dataType: 'json',
success: function(data) {
console.log('%o',data);
console.log(JSON.stringify(data));
if (data.finalReportFlag == 'success') {
alert("上报成功");
location.reload();
} else {
alert("上报失败");
}
}
});
}
</script>