I'm trying to send json object from Android device to PHP to insert it to database, but server can't find it. What I did wrong? Thanks.
Script fails in isset check.
PHP Script:
<?php
$json_array = json_decode($_POST['messages']) -> messages;
if(isset($json_array))
{
//connect to database and do insertions.
} else
{
echo "Not found array with messages in POST request\n";
}
Post request contains:
{"messages":[{"message":"Hello. Test from ukraine","id":1,"from_sender":"1111-111-1111","box":"2","type":"sms"}]}
And it's formed like this:
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpPost = new HttpPost(BASE_URL + "/josyko.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("messages", request.toString()));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
result = EntityUtils.toString(httpResponse.getEntity());
} catch (IOException e) {
e.printStackTrace();
}