[英]json_decode not working on WordPress
I am trying to get data from the API, I have the API URL and am getting data on my WordPress page in JSON format. 我正在尝试从API获取数据,我具有API URL,并在JSON页面上以JSON格式获取数据。
The problem is that I am not able to decode this JSON data, I had used wp_remote_get( $curl )
, 问题是我无法解码此JSON数据,我曾经使用过wp_remote_get( $curl )
,
wp_remote_retrieve_body( $curl )
$response = wp_remote_get( $curl );
$rows=wp_remote_retrieve_body( $response ) ;
json_decode($rows);
I had tried json_decode($response )
, json_decode($curl)
decode is not working with WordPress. 我试过json_decode($response )
, json_decode($curl)
解码不适用于WordPress。
Currently I am getting data by writing $row
into a test.json
file and decode written on another PHP file outside WordPress, it's working..... 目前,我正在通过将$row
写入test.json
文件并解码写入WordPress以外的另一个PHP文件来获取数据,.....
How can I decode inside WordPress? 如何在WordPress内部解码?
You can also use print_r / stripslashes / unserialize with your json data maybe json not formatted well. 您还可以对您的json数据使用print_r / stripslashes /反序列化,也许json格式不正确。
$response = wp_remote_get( $curl );
$rows = wp_remote_retrieve_body( $response ) ;
$decode = json_decode(stripslashes($rows), true);
//$decode = unserialize($rows); // you can try to use unserialize josn data in wordpress
print_r($decode);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.