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;