简体   繁体   中英

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.

The problem is that I am not able to decode this JSON data, I had used 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.

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.....

How can I decode inside WordPress?

You can also use print_r / stripslashes / unserialize with your json data maybe json not formatted well.

$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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM