Home  >  Article  >  php教程  >  json 无法解析解决方法

json 无法解析解决方法

WBOY
WBOYOriginal
2016-06-06 19:41:272499browse

json 无法解析 跟大伙请教一个问题,在网站做了一个功能,加载第三方类文件发送短信,短信发送成功,把array('status'=0,'message'='发送成功')以json字符串的形式返回,现在遇到这样一个情况,返回的json字符串无法解析,如果去掉发送短信,则返回的json字符

json 无法解析
跟大伙请教一个问题,在网站做了一个功能,加载第三方类文件发送短信,短信发送成功,把array('status'=>0,'message'=>'发送成功')  以json字符串的形式返回, 现在遇到这样一个情况,返回的json字符串无法解析,如果去掉发送短信,则返回的json字符串可以正常解析, 正常字符串对比无法解析的字符串没发现有不同的地方


------解决思路----------------------
可以解释到,估计你贴的不是错误的json
<br />
<?php<br />
$s = '{"status":1,"message":"\u5347\u7ea7\u4e2d\uff01"}';<br />
$arr = json_decode($s,true);<br />
print_r($arr);<br />
?><br />



Array
(
    [status] => 1
    [message] => 升级中!
)

------解决思路----------------------
引用:
复制字符串?{"status":1,"message":"\u5347\u7ea7\u4e2d\uff01"} 到json解析工具里 http://www.bejson.com/   无法解析提示  Unexpected token ? 错误


这个工具单独去处理json,是有问题的,所以你提供的json串是正确的。
------解决思路----------------------
$url = 'http://bbs.csdn.net/topics/391832102';<br />
$s = file_get_contents($url);<br />
$w = iconv('gbk',&nbs【本文来自鸿网互联 (http://www.68idc.cn)】p;'utf-8', '复制字符串'); //我习惯用 gbk 环境<br />
preg_match("/$w(.+})/", $s, $m);<br />
echo bin2hex($m[1]), PHP_EOL;<br />
echo substr($m[1], 3);
efbbbf7b22737461747573223a312c226d657373616765223a225c75353334375c75376561375c75346532645c7566663031227d<br />
{"status":1,"message":"\u5347\u7ea7\u4e2d\uff01"}<br />
那个 efbbbf 不就是 BOM 头吗?
------解决思路----------------------
来来来,预览验证一下数据,模拟一下请求
http://jsonohyeah.com
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