Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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