Jump to content

JSON decode returning null?


Veltu

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
https://forums.phpfreaks.com/topic/292312-json-decode-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.