JSON.parse() Uncaught SyntaxError: Unexpected token 让特殊字符原形毕露

<?php
$content = "测试:
测试                            测试。
测试
测试
测试";
$content =  json_encode($content);
?>
<script>
    var content = '<?=$content?>';
    content = JSON.parse(content);
    console.log(content)
</script>

<?php
$content = "测试:
测试                            测试。
测试
测试
测试";
$content =  json_encode($content);
?>
<script>
    var content = '<?=$content?>';
    content = JSON.stringify(content);
    console.log(content)
</script>

特殊字符原形毕露了  使用JSON.stringify()  等于转了2次JSON字符串

猜你喜欢

转载自www.cnblogs.com/phper8/p/12522932.html