无法解码yii2中的json字符串

时间:2017-10-22 11:37:27

标签: php json yii2

我在点击按钮时调用API。 API会向我返回json响应,我希望得到value,但我收到此错误stdClass Object ( [Message] => An error has occurred. )

我正在使用CURL进行API调用。我收到了回复,但是当我想解码它时,它给了我错误。以下是代码。

 $curl = curl_init($api_url);
.....
 $curl_response = curl_exec($curl);
$json=json_decode($curl_response);
             print_r($curl_response);
             die();
             $meter_alive= $json->data->Response; // getting error here in the web
...

curl_response{"data":{"Response":"No"}}json encoded回复为stdClass Object ( [Message] => An error has occurred. )

我还尝试将$json=json_decode($curl_response);更改为$json=json_decode($curl_response, true);,将$json=json_decode($curl_response);更改为$json=(array)json_decode($curl_response);

但我仍然无法得到结果。我不知道实际问题是什么。

任何帮助都将受到高度赞赏。

0 个答案:

没有答案