Your JSON is not here:
$json = $_SERVER['HTTP_JSON'];
Perhaps this meant:
$json = $_POST['HTTP_JSON'];
Where HTTP_JSON is the name of the POST variable that you passed to your JSON in your Android application.
The remaining errors are due to the fact that json_decode fails because you did not have time to read the JSON data from the request. You can check json_decode answer to check if it was successful as follows:
$data = json_decode($json,true); if( $data === NULL) { exit( 'Could not decode JSON'); }
Finally, passing true as the second parameter to json_encode means that it will return an associative array, so you will get access to these elements:
$name = $data['name']; $pos = $data['position'];
Be sure to read the docs for json_encode to understand what it does.
Edit: The problem is that you are accessing the $_POST parameter by the wrong name. You should use:
$json = $_POST['jsonpost'];
Since the next line contains the parameter "jsonpost":
httppost.getParams().setParameter("jsonpost",postjson);
nickb
source share