我正在从富文本区域检索文本并尝试放入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。
我知道问题是什么,问题是'几个问题后的空间'。因为我解析了这个,没关系
{"content":"<p>Mauritian politics is vibrant and characterised by severak problems.Some of them are coalition...","title":"sdddddddddddddddddddddddddddddddddddddddddddddd","interestId":"11","commentType":"Post"}
答案 0 :(得分:0)
json_decode()由于新行而失败。要将新行嵌入JSON,请使用“\ n”。例如:
<?php
$a = 'test
test
cheese';
echo json_encode(array($a));
?>
输出:
["test\ntest\ncheese"]