i am trying to send some user data (its registration android page) to my server host but there is an error while trying to get json object from server side, so how can i fix this problem?
update :: i am using byethost services and i understand that there is something with cookies. so how can i solve this problem using volley library?
i have a method called onResponse() in my RegisterActivity class and its where the problem begins. in this method i wrote this line which always throws exception about not converting string to json object which i think there is nothing to do with my java codes, the reason it cant convert string to json i guess is that its not a valid json object. but i dont know why it is not valid.
here is my register.php file https://www.androidtutorialpoint.com/wp-content/uploads/2016/09/register.txt https://www.androidtutorialpoint.com/wp-content/uploads/2016/09/update_user_info.txt https://www.androidtutorialpoint.com/wp-content/uploads/2016/09/android_login_connect.txt https://www.androidtutorialpoint.com/wp-content/uploads/2016/09/android_login_config.txt
by the way i i just followed a tutorial i do not know so much about php.
here is the method in my RegisterActivity class where the exception triggers.
@Override
public void onResponse(String response) {
Toast.makeText(RegisterActivity.this, response,
Toast.LENGTH_LONG).show();
Log.d(TAG, "Register Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) {
String user =
jObj.getJSONObject("user").getString("name");
Toast.makeText(getApplicationContext(), "Hi " + user +
", You are successfully Added!",
Toast.LENGTH_SHORT).show();
// Launch login activity
Intent intent = new Intent(
RegisterActivity.this,
LoginActivity.class);
startActivity(intent);
finish();
} else {
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
i expect to have a valid json object to pass the user data to my server but what i already have is some invalid json which throws exceptions.