Gson解析Json 四
来源:互联网 发布:天津职业大学赛尔网络 编辑:程序博客网 时间:2024/06/07 11:43
代码:
import java.util.ArrayList;import java.util.List;import bean.Datas;import bean.Girl;import bean.Product;import bean.Response;import com.google.gson.Gson;import com.google.gson.GsonBuilder;public class FourTest {public static void main(String[] args) {Gson gson=new GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create();List<Product> listP=new ArrayList<>();for (int i = 0; i < 5; i++) {listP.add(new Product(i*2+5, i*5+3+i));}List<Girl> listG=new ArrayList<>();for (int i = 0; i < 3; i++) {listG.add(new Girl(i, "Girl Name id: "+i, i>2?"男":"女", i>2?"18":18+i+""));}Response response=new Response(true, "登陆成功", "200");List<Datas> list=new ArrayList<Datas>();list.add(new Datas("girl ", listG));list.add(new Datas("product ",listP));response.setData(list);String responseJson=gson.toJson(response);System.out.println("Response格式数据:");System.out.println(" "+responseJson);}}输出内容:
0 0
- Gson解析Json 四
- java解析json(四):gson
- JSON解析 GSON解析
- json解析:gson解析json
- Gson解析Json数据
- 使用Gson解析Json
- Android JSON Gson 解析
- 使用Gson解析json
- Gson解析json
- Gson解析Json数据
- 使用Gson解析json
- Gson解析Json步骤
- Gson解析Json
- JSON解析之-Gson
- Gson解析json
- Gson解析json
- json解析-Gson
- JSON 之GSON 解析
- 指向学生类的指针
- 属性储存工具类SpUtils
- error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- Jenkins 让服务一直运行即使Job已经结束
- LeetCode:Search in Rotated Sorted Array
- Gson解析Json 四
- Java NIO原理图文分析及代码实现
- dev-C++调试崩溃问题
- Factorial Trailing Zeroes
- error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- HDU 5157 Harry and magic string (BestCoder Round #25 D) Manacher(或 Palindromic Tree) + 前缀和
- c# 类
- J2EE基础总结(1)——J2EE入门
- android 开发 多屏适配