我需要将取出的数据拼接到一个json数据中,模板转换,将键值对的数据转成xml数据,然后去转成的xml部分数据放入新的模板JSON数据中
GetMethod pm = new GetMethod("http://192.168.1.104:8888/helloworld");//xml的地址
public String loadJson() {
String resp = null;
// 构造HttpClient的实例
HttpClient hc = new HttpClient();
int code;
try {
// 执行getMethod
code = hc.executeMethod(pm);
// 如果地址正确接收数据,将数据放字符串resp里
if (code == 200) {
// 读取内容
resp = pm.getResponseBodyAsString();
}
// 处理内容
System.out.println(resp);
} catch (HttpException e) {
// 发生致命的异常,可能是协议不对或者返回的内容有问题
System.out.println("Please check your provided http address!");
e.printStackTrace();
} catch (Exception e) {
// 发生网络异常
e.printStackTrace();
} finally {
// 释放连接
pm.releaseConnection();
}
return resp;
}