我是安卓新手。我有一个休息 API 发布方法。我必须向 API 提供电子邮件和密码。它将提供 json 格式的响应,如下所示
{
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;
}
最后两个说法不正确。我把它当作一个不应该做的字符串来处理