StringBuilder stringBuilder = new StringBuilder("[");
String ssString;
ArrayList<CompetitionsByCity> ccs =competitionMapper.getCmptList(hashMap); for (CompetitionsByCity tmp:ccs)
{ stringBuilder.append("{\"cmptId\":"+"\""+tmp.getCmptId()+"\""+","+"\"cmptName\":"+"\""+tmp.getCmptName()+"\""+","+
"\"duration\":"+"\""+tmp.getDuration()+"\""+","+"\"cmptStarLevel\":"+"\""+tmp.getCmptStarLevel()+"\""+","+"\"cmptCapacity\":"+"\""+tmp.getCmptCapacity()+"\""+","+"\"cmptLength\":"+"\""+tmp.getCmptLength()+"\""+
"\"cmptFavorByMe\":"+"\""+"0"+"\""+","+"\"imgId\":"+"\""+tmp.getImgId()+"\""+"},"); //stringBuilder.append(stringBuilder); }
下面是使用Gson
String ssString;
ArrayList<CompetitionsByCity> ccs = competitionMapper
.getCmptList(hashMap);
Gson gson = new Gson();
String str = gson.toJson(ccs);
ssString = "\"size\":" + ccs.size() + "," + "\"cmptList\":" + str;
return ssString;