Re: [请益] JSON编码"{"编码有问题

楼主: wild0921 (我要幸福)   2014-10-27 13:13:06
※ 引述《wild0921 (我要幸福)》之铭言:
: ※ 引述《wild0921 (我要幸福)》之铭言:
: : 想要请问各位PHP大人,
: : 我日前建立一个webservice, 发生一个问题,
: : 我试用php 5.3.2 版本
: : 建立一个array 用json_encode 产生 json string
: : 让其它网页去接,
: : echo 出来 画面看起来是对的, 但是用json_decode 却发生问题,
: : 检查发现主要原因, 是json string 一开始的 "{" 编码有问题, 造成无法转变成Object,
: : 但我在webservice 那一页自己 json_encode 再 json_decode 却可以转成Object
: : 想要请问一下, 有没有人碰过这种问题, 是用什么方法解决?
: : 感谢......
: 有用nodepad++检查过, 档案是utf-8 无Bom档头
: 产json那一个档案也是utf-8 无Bom档头
: A.php 网页内容(捞json的网页):
: $ch = curl_init();
: curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
: curl_setopt($ch, CURLOPT_URL, $str_url);
: curl_setopt($ch, CURLOPT_POST, true); // 启用POST
: curl_setopt($ch, CURLOPT_POSTFIELDS, $_GET);
: curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
: curl_setopt($ch, CURLOPT_USERPWD, '帐号:密码');
: curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
: curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
: $output = curl_exec($ch);
: B.php 网页内容(产json string 的网页)
: die(json_encode($array));
: A.php的部分code是我用curl捞资料的方式,
: 不过那边json_decode($output); dump 出来是null,
: 检查之后 原因是json格式有问题,
: 我把所有程式码, 产新的档案在重新上传,
: 有改善的是在B.php 那一页dump出来, string检查结果格式是 通过 的
: 但是在A.php var_dump($output); 贴到检查json网页
: 格式就会错误, 死在第一个大括号
: 所以想要请问有没有人遇到过一样的状况, 然后提供一下解决方法?
json_string:贴不上去, 所以给网址
http://wildhuang.blogspot.tw/p/jsonstring.html
我用来检查json string的网址:
http://www.freeformatter.com/json-formatter.html
以上
作者: hit1205 (帮你把勇气装满)   2014-10-27 13:36:00
你贴的字串开头有个 %EF%BB%BF 字符 (就是 BOM)
楼主: wild0921 (我要幸福)   2014-10-27 14:01:00
不好意思, 可以分享一下是怎样检查出来的吗?因为我选择的档案上面是显示无bom开头

Links booklink

Contact Us: admin [ a t ] ucptt.com