试图获得 属性 个非对象
Trying to get property of non-object
我通过 Android
的请求
$request = Slim::getInstance()->request()->getBody();
$final = json_decode($request);
echo '{"test": ' . $final->name . '}';
其中,
$request = "{\"name\":\"xxxx\"}"
而 运行 它给出了 Trying to get 属性 of non-object 错误消息
您似乎对对象进行了两次编码(反斜杠让我这么认为)。所以,解码对象两次可能会解决这个问题:
$final = json_decode(json_decode( $request ));
或者,一开始就不要编码两次。你也可以去掉斜杠然后解码。
我通过 Android
的请求$request = Slim::getInstance()->request()->getBody();
$final = json_decode($request);
echo '{"test": ' . $final->name . '}';
其中,
$request = "{\"name\":\"xxxx\"}"
而 运行 它给出了 Trying to get 属性 of non-object 错误消息
您似乎对对象进行了两次编码(反斜杠让我这么认为)。所以,解码对象两次可能会解决这个问题:
$final = json_decode(json_decode( $request ));
或者,一开始就不要编码两次。你也可以去掉斜杠然后解码。