21,893
社区成员




<?php
$test = '{"FullName":"1234567","UserName":"test2"}';//测试数据成功
$test_json = json_decode($test);
error_log("test_json->FullName = ". $test_json->FullName);
//接受android post 请求的类似json格式的字符串数据({"FullName":"1234567","UserName":"test2"})
$obj = file_get_contents("php://input");
error_log(" obj1 == ".$obj);
$obj = "'".$obj ."'";
error_log(" obj2 == ".$obj);
$json = json_decode($obj);
//如果$obj不加单引号,则报类型转换异常,加了单引号之后json_decode($obj),又没有数据输出
//$obj = {"FullName":"1234567","UserName":"test2"};
//<b>Catchable fatal error</b>: Object of class stdClass could not be converted to string in <b>D:\Web\www\book\AppCart.php</b> on line <b>21</b><br />
// 用json_encode也不能$json->UserName输出数据
// $json = json_encode($obj);
// "{\\"FullName\\":\\"1234567\\",\\"UserName\\":\\"test2\\"}"
error_log(" json== " . $json);
$username = $json->UserName;
$fullname = $json->FullName;
error_log("+++++UserName++++" . $username);
error_log("++++++fullname==++++" . $fullname);
?>