自己拼接json字符串,现在用Gson来实现
2024-10-19 12:41:15
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;
最新文章
- Servlet下载文件和http响应
- ubuntu下mysql的常用命令,MySQL数据库的基本操作命令
- 常用sql,在做项目时用mysqlWorkBeach里面自动生成的
- #define x do{......} while(0)的用处
- zzzzw_在线考试系统③完结篇
- Tomcat基础教程(二)
- Shell脚本常用命令简介
- 基于visual Studio2013解决C语言竞赛题之0401阶乘
- Oracle 11g client安装和配置。
- 使用js在新窗口中POST数据
- python3实现TCP协议的简单服务器和客户端
- 关于JS中获取浏览器高度和宽度值的多种方法(多浏览器)
- Typora使用说明(记录总结)
- 大端&;小端问题
- How to distinguish between strings in heap or literals?
- ABC3
- Java Base64 编码解码方案总结
- 构造函数 (C++)
- 2018.09.16 loj#10243. 移棋子游戏(博弈论)
- Windows 上 GitHub Desktop 的操作[转]