Jump to content

json_encode returning null


Staggan

Recommended Posts

Hello

 

I am having an issue with encoding an array to JSON, my array seems to be formed correctly but when I try and echo the json_encode version I get "null". I echo the JSON error code and it is "0" indicating no issue.. 

 

I have read that non UTF-8 characters can be an issue, but this is simple data, no strange characters... but I added the utf8_encode anyway....

 

Here is my code:

$dataArray = array( 
 
'title' => 'Test Item',
'icon_url' => 'http://url/api/testimage.jpg',
'item_id' => '12345',
'expiration' => 600 
);
 
utf8_encode($dataArray);
 
$responsArray = array( 
 
'success' => '1',
'data' => $dataArray
);
 
 
utf8_encode($responsArray);
 
header('Content-type: application/json');
 
echo print_r($responsArray);
echo json_encode ($responseArray);
echo json_last_error();
 
 
Any thoughts would be appreciated
 
Link to comment
https://forums.phpfreaks.com/topic/293163-json_encode-returning-null/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.