我是一个新的android。我有一个休息的API发布方法。我必须提供电子邮件和密码给API。它将提供这将是JSON格式像下面在post方法中处理json响应android
{
error: "This email is already registered "
status: 404
}
格式的原始响应将在形式如下
{"error":"This email is already registered\n","status":404}
我发送的名称值对成功的响应,但我不不知道如何处理这种类型的回应。任何人都可以帮我解决这个问题吗?这里是我的代码
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;
}
最后两条语句不正确。我处理,作为一个字符串,它不应该做的
正如你所说,你确实取得了成功。之前。什么是状态代码。因此,您可以比较'resp'字符串的状态并查找是否成功 – MDMalik 2015-02-05 17:02:53