使用PHP检索保存为mysql数据库文本的JSON数据


Retrieving JSON data that is saved as text in mysql database using PHP

我有一个表单与元素的数量,我编码所有的数据从表单使用json_encode($_POST),并将其保存到mysql数据库。

这是我在mysql数据库中的JSON数据

{"sections":{"int":{"section_name":"Interests","data":"These are my interests"},"ref":{"section_name":"Referance","data":"This Is my referance"},"other":{"section_name":"other","data":"This Is my referance"}}}

保存到mysql的JSON数据格式良好。我复制/粘贴数据从mysql数据库到jsoneditoronline。org并检查错误。JSON数据没有任何错误。

现在当我使用mysql查询检索相同的JSON数据时,

JSON中的开始双引号被“结束双引号被”

所以我不能使用JSON数据。我怎么能得到准确的JSON数据从mysql表?

我正在使用wordpress内置函数来检索JSON数据

$id=366; 
$post = get_page($id);
$JSON = apply_filters('the_content', $post->post_content); 
echo $JSON; 

根据mysql数据库中存储的数据,$JSON应该是有效的JSON,但它被html特殊字符自动替换。

如何克服这一点?

如何通过mysql查询从mysql数据库获得有效的JSON ?

html_entity_decode (http://php.net/manual/en/function.html-entity-decode.php)或urldecode (http://php.net/manual/en/function.urldecode.php)

可能帮助。

使用json_encode($jsonarray, JSON_UNSCAPED_SLASHES);