项目场景:
richMail邮件列表信息获取
问题描述
将获取的邮件信息由JSON格式转成list对象格式,转换的过程没有报错,但内容都是空的
public static void main(String[] args) { String userEmail = "1234@xxx.com"; HttpClientManager http = HttpClientManager.newClient(); String url = "邮件路径/webmail/service/api.do?func=mbox:listMessages&email="+userEmail; String order = "desc"; String param = "{\"order\":\""+order+"\",\"fid\":1,\"start\":0,\"total\":200,"+ "\"flags\":1}"; String resultStr = HttpUtil.post(url,param); if(StringUtils.isNotBlank(resultStr)){ Map<String, Object> map = JsonTools.json2Map(resultStr); if("S_OK".equals(map.get("code"))){ List<RichMailVO> list= JSON.parseArray(JSON.toJSONString(map.get("var")), RichMailVO.class); } } }
原因分析:
返回的对象里还存在对象
解决方案:
public static void main(String[] args) {
String userEmail = "1234@xxx.com";
HttpClientManager http = HttpClientManager.newClient();
String url = "邮件路径/webmail/service/api.do? func=mbox:listMessages&email="+userEmail;
String order = "desc";
String param = "{\"order\":\""+order+"\",\"fid\":1,\"start\":0,\"total\":200,"+ "\"flags\":1}";
String resultStr = HttpUtil.post(url,param);
if(StringUtils.isNotBlank(resultStr)){
Map<String, Object> map = JSONObject.parseObject(JSONObject.parse(resultStr).toString(),Map.class);
if("S_OK".equals(map.get("code"))){
List<RichMailVO> list= JSON.parseArray(JSON.toJSONString(map.get("var")), RichMailVO.class);
}
}
}