我有一个从 a 返回 json 编码响应的函数$_POST
:
function getdatafrompost(){
$raw = '';
$httpContent = fopen('php://input', 'r');
while ($kb = fread($httpContent, 1024))
$raw .= $kb;
fclose($httpContent);
$params = array();
parse_str($raw, $params);
if (isset($params['data']))
$retdata = json_decode(stripslashes($params['data']));
else
$retdata = json_decode(stripslashes($raw)); <====Returns Null
return $retdata;
}
正在读取的原始数据是:
{"recordid":"099ac8aa-0a43-11e2-860f-0016177c526f","ntsdataid":"","trkdataid":"5628af8e-08db-11e2-860f-0016177c526f","activitydate":"2012-09-29","activitytime":"10:36:21","activityname":" from S. Interrante","activitynote":"<i><font color=\"99CC00\" size=\"4\"><b><font face=\"verdana\">fgsdfgsdgsdfgsdgsdgsdfg</font>\u200b</b></font></i>"}
问题$retdata
是返回null。这似乎在包含 HTML 的“activitynote”字段中。当“activitynote”不包含 HTML 时,数据会被正确解析。有没有更好的方法来解析数据?我做错了什么吗?