Android如何传输参数给一个url接口 参数是json格式
展开全部
一般传输参数使用json类型或者map类型都是使用post方法。
使用json数据格式发送信息向服务器端:
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpPost = new HttpPost(BASIC_URL + url);
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
JSONObject jsonObject = new JSONObject();
JSONObject jsonObject2 = new JSONObject();
jsonObject.put("uemail", userbean.getEmail());
jsonObject.put("password", userbean.getPassword());
jsonObject2.put("userbean", jsonObject);
nameValuePair.add(new BasicNameValuePair("jsonString", jsonObject
.toString()));
Log.i("lifeweeker", jsonObject2.toString());
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
}
使用json数据格式发送信息向服务器端:
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost httpPost = new HttpPost(BASIC_URL + url);
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
JSONObject jsonObject = new JSONObject();
JSONObject jsonObject2 = new JSONObject();
jsonObject.put("uemail", userbean.getEmail());
jsonObject.put("password", userbean.getPassword());
jsonObject2.put("userbean", jsonObject);
nameValuePair.add(new BasicNameValuePair("jsonString", jsonObject
.toString()));
Log.i("lifeweeker", jsonObject2.toString());
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询