我有JSON,它已保存在我网站的文本框中,并保存到下面的数据库中。{"@type":"GOOOGLE.COM","@id":"GOOGLE","url":"GOOGLE","inLanguage":"en-US","name":"dfghjk | Bloomberg Professional Services","isPartOf":{"@id":"GOOGLE,"datePublished":"2020-02-11T21:51:45+00:00","dateModified":"2020-02-11T21:51:45+00:00"}]}我想将其转换为PHP中的正确外观,如下所示:{"@type":"GOOOGLE.COM","@id":"GOOGLE","url":"GOOGLE","inLanguage":"en-US","name":"dfghjk | Bloomberg Professional Services","isPartOf":{"@id":"GOOGLE,"datePublished":"2020-02-11T21:51:45+00:00","dateModified":"2020-02-11T21:51:45+00:00"}]}我试着做了一个json_encode但它不起作用。如何将带有所有这些转义引号等的字符串转换为PHP中的普通json字符串?我试过这样: $str = "{"@type":"GOOOGLE.COM","@id":"GOOGLE","url":"GOOGLE","inLanguage":"en-US","name":"dfghjk | Bloomberg Professional Services","isPartOf":{"@id":"GOOGLE,"datePublished":"2020-02-11T21:51:45+00:00","dateModified":"2020-02-11T21:51:45+00:00"}]}" $data = json_encode($str, true); return $data;
1 回答
一只名叫tom的猫
TA贡献1906条经验 获得超3个赞
您需要将 HTML 实体解码回字符:
https://www.php.net/manual/en/function.htmlspecialchars-decode.php
$json = htmlspecialchars_decode($str, true); // valid json string
$data = json_decode($json); // convert json to php data structure
return $data;
- 1 回答
- 0 关注
- 104 浏览
添加回答
举报
0/150
提交
取消