Jump to content

JSON decode returning null?


Veltu
Go to solution Solved by Barand,

Recommended Posts

Hi all,

 

I'm posting JSON to an API call. If I use a var_dump within the API it will return correctly, although if I try to var_dump within the function it will return NULL.

 

API:

$json = file_get_contents('php://input');


if(isset($_GET['form_id']) && intval($_GET['form_id'])>0)
{
if(isset($json))
{


$records = $questionnaire->logFormAnswers($_POST['answers'],$_GET['form_id']);

Then using the logFormAnswers function...

 

Function:

public function logFormAnswers($answers = "", $form_id = 0)
{


$answers = json_decode($json,true);
var_dump($answers);

The JSON:

[{"question_id":"3","answer":"dsf"},{"question_id":"3","answer":"sdfsdfdsfsd"}]

Eventually, once the JSON has been decoded, it will be inserted into a database within the function.

 

If anyone can see what I'm doing wrong, any help is appreciated, thanks!

Link to comment
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.