我正在从富文本区检索文本,并试图放入json。我有一个这样的json:
{"content":"<p>Mauritian politics is vibrant and characterised by several problems.
Some of them are coalition...","title":"sdddddddddddddddddddddddddddddddddddddddddddddd","interestId":"11","commentType":"Post"}
现在,当我试图在php中解析上面的json时,它失败了,给我一个空白的json。
我知道问题是什么,问题是空格后面有几个问题。因为我解析了这个,它是ok
{"content":"<p>Mauritian politics is vibrant and characterised by severak problems.Some of them are coalition...","title":"sdddddddddddddddddddddddddddddddddddddddddddddd","interestId":"11","commentType":"Post"}
json_decode()由于新行而失败。要在JSON中嵌入新行,使用"n"。如:
<?php
$a = 'test
test
cheese';
echo json_encode(array($a));
?>
这个输出:["testntestncheese"]