When I try to retrieve a JSON object from an API, it causes an error. I'm using JSONObjectRequest
to get the result.
This is my activity method:
private void execute(final Context context) {
String url = UrlManager.getUrl(context, R.string.signup_url);
User user = User.getInstance();
try {
url += "&name=" + mFirstName + "&last=" + mLastName + "&mob=" + mMobile +
"&email=" + mEmail +
"&pass=" + UrlManager.prepareUrlPart(mPassword);
} catch (Exception e) {
e.printStackTrace();
}
final ProgressDialog pDialog;
pDialog = new ProgressDialog(context);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
pDialog.show();
Response.Listener < JSONObject > listener = new Response.Listener < JSONObject > () {
@Override
public void onResponse(JSONObject response) {
try {
JSONObject userObj = new JSONObject();
userObj = response; //response.getJSONObject("UserInfo");
userInfo = new UserInfo();
userInfo.LoadItem(context, (JSONObject) userObj);
String state = response.getString("State");
if (state == "1") {
// Load user data from json and save them into local database
// User user = User.getInstance();
// user.loadFromJSon(response);
/// user.saveUser();
onResult(true);
} else {
onResult(false);
}
} catch (Exception e) {
Log.d("Error", e.getMessage());
e.printStackTrace();
}
pDialog.dismiss();
}
};
Response.ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, "Error", Toast.LENGTH_LONG).show();
pDialog.dismiss();
}
};
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, null, listener, errorListener);
MyApplication.getInstance().addToRequestQueue(request);
}
I've assured that my JSON is non-empty. Here's a sample JSON result:
{"UserId":60,"UserName":"09111","Password":"123","Email":"m@m.com","Mobile":"09111111111","NationalId":"0000000000","FirstName":"mm","LastName":"mm","FatherName":"","Birthday":"1990/10/11","State":"1"}
This is the error in question:
org.json.JSONException: End of input at character 0 of