PHP - json_decode() returns null when using echo
Posted
by
ShatouDev
on Stack Overflow
See other posts from Stack Overflow
or by ShatouDev
Published on 2012-09-02T03:05:59Z
Indexed on
2012/09/02
3:38 UTC
Read the original article
Hit count: 228
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"
}
© Stack Overflow or respective owner