通过 HttpUtil.post发送请求获得的是一串字符串 String content2 = HttpUtil.post(SystemInitParams.SmsServicePath + “/smsTemplates/getSmsTemplatesAll”,"");
eg:字符串[{“id”:1,“name”:“jeck”},{“id”:2,“name”:“lily”}]
将[{“id”:1,“name”:“jeck”},{“id”:2,“name”:“lily”}]转json:
String content2 = HttpUtil.post(SystemInitParams.SmsServicePath + "/smsTemplates/getSmsTemplatesAll","");
//先将字符串转json数组
JSONArray jsonList = JSON.parseArray(content2);
System.out.println(request.getParameter("smsTemplates"));
//循环遍历
for (Object o:jsonList){
JSONObject object = JSONObject.parseObject(o.toString());
if(request.getParameter("smsTemplates").equals(object.getString("id"))){
String[] str= object.getString("parameter").split(",");
for (int i=0;i<str.length;i++){
param.put(str[i],request.getParameter(str[i]));
}
}
}