请问为什么,json_decode转uft-8字符串,结果为null?
<html> <html><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8"/></head><br><?php<br><br>$str=isset($_POST["text"]) ? filter_input(INPUT_POST,"text",FILTER_SANITIZE_SPECIAL_CHARS) : '';<br>print "$str=".$str."\n";<br>if (strlen($str)>0){<br>//$str=mb_convert_encoding($str,"GBK","UTF-8");<br>$jo=json_decode($str); //中文的,转出来是null<br>print_r("\n++++\n".$jo."\n====\n"); <br>$msg_id=$jo->msg_id; //这里就会报错了。<br>}<br><br><br>echo ' <form method="post" action="t1.php">';<br>echo ' <textarea name="text" rows="2" cols="80">{"name":"test","id":0,"txt":"中文"}</textarea><br>';<br>echo ' <input type="submit"></form>';<br><br><br>?>------解决方案--------------------
json 格式不对吧 ,你把j要转换的json字符串echo 出来看看 是否符合标准json格式
------解决方案--------------------
加上后面的
已经不是json格式了。
------解决方案--------------------
print_r("\n++++\n".$jo."\n====\n");
这里是什么?
------解决方案--------------------
echo $_post["text"];
看看是什么,多半是引号被转义了










