Home  >  Article  >  Backend Development  >  api-php中url接收的json数据,json_decode为空

api-php中url接收的json数据,json_decode为空

WBOY
WBOYOriginal
2016-06-02 11:29:151526browse

phpapijson手机服务器与客户端通信

#php后台json数据decode为结果空#
我使用手机传输数据到php后台,json_decode的结果为空。
手机传输的方式为POST/GET,编码格式为UTF-8。
json数据为(包括代码中的单引号,我用字符串传输,json数据中必须为双引号):

<code>   '{"agent":"30","job":"1133","students":[{"working_hours_unit":"null","working_hours":"6","student_id":"191","commission_unit":"null","wage":"58","commission":"348","wage_unit":"null"}]}'</code>

php代码获取到了以上json数据,并且能够使用echo输出。php代码:

<code> $str=$_GET('my_str'); echo $str;</code>

输出测试结果然后我接着decode接收到的json数据,代码:

<code> $form = json_decode($Noel,true); var_dump($form);</code>

但很意外输出为**null** ,然后我用_echo json_last_error();_输出json转换错误,结果为4===json语法错误。
附上完整代码和截图:

<code>     $str=$_GET('my_str');  echo $str;$form = json_decode($str,true); var_dump($form); echo json_last_error();</code>

页面输出结果
但是,当我把接收到的json单独接到PHP代码中,然后decode却能够正确解析。(我内心是崩溃的 〒_〒)
代码:`

<code>     $orm='{"agent":"30","job":"1133","students":[{"working_hours_unit":"null","working_hours":"6","student_id":"191","commission_unit":"null","wage":"58","commission":"348","wage_unit":"null"}]}';  $arr=json_decode($form,true);  var_dump($arr);</code>

截图:
图片说明

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