$customer = json_decode(file_get_contents("php://input"));
var_dump($this->get_request_method());
var_dump($customer);
json_decode return NULL and i don't understand why.PHP has ways of discerning the errors in JSON strings.
<?php // demo/json_decode_show_errors.php
/**
* JSON stands for JavaScript Object Notation
* http://json.org/
*
* JSON support in PHP does not have very good error handling
*
* JSON strings are all UTF-8
* http://www.experts-exchange.com/articles/11880/Unicode-PHP-and-Character-Collisions.html
*
* PHP man page references
* http://php.net/manual/en/json.constants.php
* http://php.net/manual/en/function.json-decode.php
* http://php.net/manual/en/function.json-encode.php
* http://php.net/manual/en/function.json-last-error.php
* http://php.net/manual/en/function.json-last-error-msg.php
*/
error_reporting(E_ALL);
echo '<pre>';
// SEE TEST DATA AT http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28523915.html#a40339939
$jso = <<<EOD
{"id":"tag:search.twitter.com,2005:389903668427763712","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:91239297","link":"http://www.twitter.com/OGkush103","displayName":"WalkingLick74","postedTime":"2009-11-20T01:21:39.000Z","image":"https://si0.twimg.com/profile_images/378800000593715086/755411d8bdc495472c2d7ed50e319582_normal.jpeg","summary":"Self-Made, Self Paid..... I always had the mind to get it like a man, head first bout my younging Ean! #YOLO","links":[{"href":null,"rel":"me"}],"friendsCount":468,"followersCount":677,"listedCount":0,"statusesCount":25504,"twitterTimeZone":"Alaska","verified":false,"utcOffset":"-28800","preferredUsername":"OGkush103","languages":["en"],"location":{"objectType":"place","displayName":"Boston George Crib"},"favoritesCount":26},"verb":"post","postedTime":"2013-10-15T00:00:53.000Z","generator":{"displayName":"Twitter for iPhone","link":"http://twitter.com/download/iphone"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/OGkush103/statuses/389903668427763712","body":"You a killer you on twitter, You'n do NO talking","object":{"objectType":"note","id":"object:search.twitter.com,2005:389903668427763712","summary":"You a killer you on twitter, You'n do NO talking","link":"http://twitter.com/OGkush103/statuses/389903668427763712","postedTime":"2013-10-15T00:00:53.000Z"},"favoritesCount":0,"location":{"objectType":"place","displayName":"Mississippi, US","name":"Mississippi","country_code":"United States","twitter_country_code":"US","link":"https://api.twitter.com/1.1/geo/id/43d2418301bf1a49.json","geo":{"type":"Polygon","coordinates":[[[-91.65500899999999,30.146096],[-91.65500899999999,34.996099],[-88.097888,34.996099],[-88.097888,30.146096]]]}},"geo":{"type":"Point","coordinates":[31.99686058,-88.72688823]},"twitter_entities":{"hashtags":[],"symbols":[],"urls":[],"user_mentions":[]},"twitter_filter_level":"medium","twitter_lang":"en","retweetCount":0,"gnip":{"matching_rules":[{"tag":null}],"language":{"value":"en"}}}
EOD;
// IF DECODING SUCCEEDS
$obj = json_decode($jso);
if ($obj)
{
// SHOW SOME PARTS OF THE OBJECT
$x = $obj->objectType;
$y = $obj->actor->displayName;
echo PHP_EOL . "$x $y" . PHP_EOL;
// ACTIVATE THIS TO SHOW THE ENTIRE OBJECT
// var_dump($obj);
}
// IF DECODING FAILS?
if (!$obj) echo json_last_error_message();
function json_last_error_message()
{
static $errors = array
( JSON_ERROR_NONE => null
, JSON_ERROR_DEPTH => 'Maximum stack depth exceeded'
, JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch'
, JSON_ERROR_CTRL_CHAR => 'Unexpected control character found'
, JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON'
, JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
)
;
// ADD THESE AT PHP 5.5+ OR USE json_last_error_msg()
if (defined('JSON_ERROR_RECURSION')) $errors[JSON_ERROR_RECURSION] = 'One or more recursive references in the value to be encoded';
if (defined('JSON_ERROR_INF_OR_NAN')) $errors[JSON_ERROR_INF_OR_NAN] = 'One or more NAN or INF values in the value to be encoded';
if (defined('JSON_ERROR_UNSUPPORTED_TYPE')) $errors[JSON_ERROR_UNSUPPORTED_TYPE] = 'A value of a type that cannot be encoded was given';
$error = json_last_error();
return array_key_exists($error, $errors)
? $errors[$error]
: "Unknown error ({$error})"
;
}
http://json.parser.online.fr/