0
我有Json::decode
问题。我正在使用此代码:Json :: decode返回NULL
use Drupal\Component\Serialization\Json;
$client = \Drupal::httpClient();
$request = $client->post($rest_url, [
'form_params' => [
'id' => $rest_id,
],
]);
$response = Json::decode($request->getBody());
从某个服务器获取JSON,但它返回NULL。当然,这仅仅是一个部分的代码(不try
,catch
...)
$request->getBody()
回报是好的,但在Json::decode
我仍然得到NULL。我注意到的唯一的事情是在Postman中,当我看着原始的内容时,我在JSON的开头看到了一些空行(如键入时键盘上的返回键),但是我检查了JSON,因为它处于打开状态JSONLint它是有效的。
任何想法是什么问题?
看起来像Json :: decode只会调用PHP的本机'json_dcode' ...所以使用'json_last_error' /'json_last_error_msg'来找出错误。 – CBroe
是的,它的语法错误...所以我会从客户端请求固定的JSON(因为它是通过一些他们的内部软件生成的)...谢谢... – mixerowsky