Home >Backend Development >PHP Tutorial >请教为什么,json_decode转uft-8字符串,结果为null

请教为什么,json_decode转uft-8字符串,结果为null

WBOY
WBOYOriginal
2016-06-13 11:55:561045browse

请问为什么,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"];
看看是什么,多半是引号被转义了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn