PHP - json_decode() returns null when using echo
- by ShatouDev
I am using the following script to decode a json. Although the var_dump($obj) returns result (similar to one in here Example #1), the echo line doesn't return any result, as if the $obj being null.
<?php
$clientJSONObject = file_get_contents('php://input');
$obj = json_decode($clientJSONObject, TRUE);
var_dump($obj); // working.
echo $obj; // returns nothing.
echo $obj["carrier"]; // returns nothing.
?>
var_dump output:
array(2) {
["carrier"]=>
string(8) "Etisalat"
["userLanguage"]=>
string(2) "ar"
}