自己拼接json字符串,现在用Gson来实现
1 StringBuilder stringBuilder = new StringBuilder("["); 2 String ssString; 3 ArrayList<CompetitionsByCity> ccs =competitionMapper.getCmptList(hashMap); 4 5 for (CompetitionsByCity tmp:ccs) 6 { 7 8 stringBuilder.append("{\"cmptId\":"+"\""+tmp.getCmptId()+"\""+","+"\"cmptName\":"+"\""+tmp.getCmptName()+"\""+","+ 9 "\"duration\":"+"\""+tmp.getDuration()+"\""+","+"\"cmptStarLevel\":"+"\""+tmp.getCmptStarLevel()+"\""+","+"\"cmptCapacity\":"+"\""+tmp.getCmptCapacity()+"\""+","+"\"cmptLength\":"+"\""+tmp.getCmptLength()+"\""+ 10 "\"cmptFavorByMe\":"+"\""+"0"+"\""+","+"\"imgId\":"+"\""+tmp.getImgId()+"\""+"},"); 11 12 //stringBuilder.append(stringBuilder); 13 14 }
下面是使用Gson
1 String ssString; 2 ArrayList<CompetitionsByCity> ccs = competitionMapper 3 .getCmptList(hashMap); 4 Gson gson = new Gson(); 5 String str = gson.toJson(ccs); 6 ssString = "\"size\":" + ccs.size() + "," + "\"cmptList\":" + str; 7 return ssString;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。