-1

Gives null on using json_decode on facebook graph object sent from android to php.

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


$data = json_decode($json);


var_dump($data);

returns NULL when search i found this json_decode returns NULL after webservice call

used same code with all possibilities

$json =  file_get_contents('php://input');
     $json = str_replace('"', '"', $json);
    $json = trim(substr($json ,3)); 


    $data = json_decode($json);


    var_dump($data);

tried this also ,returns null

Community
  • 1
  • 1
Abhilash Aruva
  • 308
  • 3
  • 10
  • Check whether your `JSON` is valid on jslint.com – Shankar Narayana Damodaran Mar 01 '14 at 08:37
  • we are sending facebook graph object received at android to php server with some concatenation to that fb graph object. some times it is decoding fine. but some time it gives a null when decoded using json_decode, but when i echo $json = file_get_contents('php://input'); we are getting the json every time. may problem with json_decode – Abhilash Aruva Mar 01 '14 at 08:47
  • Solved i was getting a value with special characters. json_decode was not able to decode the json, so it was returning null ... – Abhilash Aruva Mar 02 '14 at 20:32

1 Answers1

0

I had faced the same problem. It is due to special characters in the String. Handle the special characters to avoid null value.

Anirudh
  • 2,767
  • 5
  • 69
  • 119