java如何在Android的Rest服务中传递列表<Integer>对象和字符串
大家好,我正在准备一个测验应用程序,所以我需要调用post rest services(json),下面是我的示例代码,它不起作用
我需要传递3个参数1-userid,2-List questionid和3-List answerid。我的问题是如何在这里传递列表对象而不是字符串或Json字符串-
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("userid", "121213"));
nameValuePairs.add(new BasicNameValuePair("questionsids", listobj);
nameValuePairs.add(new BasicNameValuePair("answerIds", listObj));
HttpClient httpclient=new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setHeader(HTTP.CONTENT_TYPE,"application/x-www-form-urlencoded;charset=UTF-8");
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
有没有其他方法可以打电话给post rest服务。如何解决上述问题
谢谢 兰扬
共 (0) 个答案