<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>json demo</title>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<script type="text/javascript">
window.onload=function () {
//方式:一:
var info="input info";
var obj = '{"aa":"bb","tt":124,"cc":"'+info+'"}';
console.log(JSON.stringify(obj));
//"{\"aa\":\"bb\",\"tt\":124,\"cc\":\"input info\"}"
console.log(jQuery.parseJSON(obj));
//{aa: 'bb', tt: 124, cc: 'input info'}
console.log(JSON.parse(obj));
//{aa: 'bb', tt: 124, cc: 'input info'}
//方式二:
var infos="input data info";
var ts={aa: 'bb', tt: 124, cc: infos}
console.log(JSON.stringify(ts));
//{"aa":"bb","tt":124,"cc":"input data info"}
}
</script>
</body>
</html>
参考:
https://api.jquery.com/jQuery.parseJSON
https://www.json.org/json-zh.html