String url = "http://120.25.102.84:8000/creditAudit";
PostMethod postMethod = new PostMethod(url);
// 填入各个表单域的值
NameValuePair[] data = {
new NameValuePair("message", JSON.toJSONString(ll))};
System.out.println("推送成功");
// 将表单的值放入postMethod中 commons-httpclient.jar
postMethod.setRequestBody(data);
postMethod.getParams().setContentCharset("utf-8");
postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");
// 执行postMethod
int statusCode = 0;
try {
statusCode = new HttpClient().executeMethod(postMethod);
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// HttpClient对于要求接受后继服务的请求,象POST和PUT等不能自动处理转发
// 301或者302
if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY
|| statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
// 从头中取出转向的地址
Header locationHeader = postMethod.getResponseHeader("location");
String location = null;
if (locationHeader != null) {
location = locationHeader.getValue();
System.out.println("diandianLogin:" + location);
} else {
System.err.println("Location field value is null.");
}
return;
} else {
System.out.println(postMethod.getStatusLine());
String str = "";
try {
str = postMethod.getResponseBodyAsString();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(str);
}
postMethod.releaseConnection();
return;
new NameValuePair("message", JSON.toJSONString(ll))}; messages是个list 但是转成json 但是 格式如下
[name=message, value=[{"BAL":"5273.84","BILLDTLS_ID":"AazLIsjsMYnlKYirmNOx","LOANID":"NJGL20160428002","PRERETUAMT":"3052.40"}]]
单我想 修改格式为:
[{"BAL":"5273.84","BILLDTLS_ID":"AazLIsjsMYnlKYirmNOx","LOANID":"NJGL20160428002","PRERETUAMT":"3052.40"}]
请问如何修改,大神勿喷
转换成jsonarray 然后遍历下得到一个
并且我这个是 模拟表单,给别人接口推送数据的
Android6.0已经不支持HttpClient了,建议你换个框架吧
什么东西 ,JsonArray.fromObject(Object obj)这个可以转list,map集合,直接不行么
String str=json.split("value="); str[1]就是你想要的,这种就用字符串分割吧。
//[name=message, value=[{"BAL":"5273.84","BILLDTLS_ID":"AazLIsjsMYnlKYirmNOx","LOANID":"NJGL20160428002","PRERETUAMT":"3052.40"}]]
//把你的JSON转换成以下格式
String json = "{\"name\":\"message\", \"value\":[{\"BAL\":\"5273.84\",\"BILLDTLS_ID\":\"AazLIsjsMYnlKYirmNOx\",\"LOANID\":\"NJGL20160428002\",\"PRERETUAMT\":\"3052.40\"}]}";
JSONObject obj = JSONObject.fromObject(json);
System.out.println(obj.get("value").toString());