I am a new to android. I have a rest API post method. I have to provide email and password to the API. It will provide the response which will be in json format like the format below
{
error: "This email is already registered "
status: 404
}
the raw response will be in the form as below
{"error":"This email is already registered\n","status":404}
I sent the name value pairs successfully but I don't know how to handle this type of response. Can anyone help me out with this? here is my code
protected String doInBackground(String... params) {
//HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://zigron.goabode.com/api/registration/new");
PostMethod post = new PostMethod("https://zigron.goabode.com/api/registration/new");
String resp=null;
try
{
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("email", email_s ) );
nameValuePairs.add(new BasicNameValuePair("password", pwd_s ) );
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
System.out.println(nameValuePairs);
resp=post.getResponseBodyAsString();
return resp;
}
last two statements are not correct. I am handling that as a string which shouldn't be done
You can use the below code for accessing Post Webservice...
This response_data will give you the whole response of your webservice as String. Now you can parse the String as per your response : Like
Parse as per your response.