I am getting json string from my android app that contains the data for user registration. In server side i am using php to insert it in to database.
Here is the json string that I will get
{"user_name":"Steve Jobs","user_email":"[email protected]","user_password":"nopassword","user_phone_number":"1234567890","club_member_id":"24"}
But when I convert it in to an array I will get null value.
<?php
//$_POST contains the json string.
$data = json_decode($_POST,true);
?>
$data will get empty string
How will I resolve it.
UPDATE
Content of file_get_contents('php://input')
POST=%7B%22user_name%22%3A%22Steve+Jobs%22%2C%22user_email%22%3A%22steave%40apple.com%22%2C%22user_password%22%3A%22nopassword%22%2C%22user_phone_number%22%3A%221234567890%22%2C%22club_member_id%22%3A%2224%22%7
JAVA
private void onSignup() throws IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
// Add your data
try {
jsonParams.put("user_name", "Steve Jobs");
jsonParams.put("user_email", "[email protected]");
jsonParams.put("user_password", "nopassword");
jsonParams.put("user_phone_number", "1234567890");
jsonParams.put("club_member_id", "24");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("POST", jsonParams.toString()));
Log.e("mainToPost", "mainToPost" + nameValuePairs.toString());
// Use UrlEncodedFormEntity to send in proper format which we need
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (JSONException e) {
}
JSONParser jParser = new JSONParser();
// Getting JSON from URL
JSONObject json = jParser.getJSONFromUrl(url);
Log.e("Data", String.valueOf(json));
try {
// Getting JSON Array
JSONArray user = json.getJSONArray("POST");
Log.e("JSON ARRAY", String.valueOf(user));
ArrayList<String> stringArray = new ArrayList<String>();
for (int i = 0, count = user.length(); i < count; i++) {
try {
JSONObject jsonObject = user.getJSONObject(i);
String name = jsonObject.getString(TAG_NAME);
stringArray.add(name);
Log.e("JSON ARRAY", String.valueOf(stringArray));
} catch (JSONException e) {
e.printStackTrace();
}
}
// name1.setText(String.valueOf(stringArray));
} catch (JSONException e) {
e.printStackTrace();
}
}
var_dump($_POST);? Post the results here.