Google_开源项目(Gson)经典完全教程.pdf

Google_开源项目(Gson)经典完全教程.pdf

ID:52794061

大小:362.55 KB

页数:12页

时间:2020-03-30

Google_开源项目(Gson)经典完全教程.pdf_第1页
Google_开源项目(Gson)经典完全教程.pdf_第2页
Google_开源项目(Gson)经典完全教程.pdf_第3页
Google_开源项目(Gson)经典完全教程.pdf_第4页
Google_开源项目(Gson)经典完全教程.pdf_第5页
资源描述:

《Google_开源项目(Gson)经典完全教程.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、1.简单的处理list和mapJava代码1.Gsongson=newGson();2.ListtestList=newArrayList();3.testList.add("first");4.testList.add("second");5.StringlistToJson=gson.toJson(testList);6.System.out.println(listToJson);7.//prints["first","second"]8.9.MaptestMap=newHashMap();10.testMap.put("id","id.first");11.te

2、stMap.put("name","name.second");12.StringmapToJson=gson.toJson(testMap);13.System.out.println(mapToJson);14.//prints{"id":"id.first","name":"name.second"}Gsongson=newGson();ListtestList=newArrayList();testList.add("first");testList.add("second");StringlistToJson=gson.toJson(testList);Sys

3、tem.out.println(listToJson);//prints["first","second"]MaptestMap=newHashMap();testMap.put("id","id.first");testMap.put("name","name.second");StringmapToJson=gson.toJson(testMap);System.out.println(mapToJson);//prints{"id":"id.first","name":"name.second"}2.处理带泛型的集合Java代码1.Listte

4、stBeanList=newArrayList();2.TestBeantestBean=newTestBean();3.testBean.setId("id");4.testBean.setName("name");5.testBeanList.add(testBean);ListtestBeanList=newArrayList();TestBeantestBean=newTestBean();testBean.setId("id");testBean.setName("name");testBeanLis

5、t.add(testBean);Java代码1.java.lang.reflect.Typetype=newcom.google.gson.reflect.TypeToken>(){2.}.getType();3.StringbeanListToJson=gson.toJson(testBeanList,type);4.System.out.println(beanListToJson);5.//prints[{"id":"id","name":"name"}]6.7.ListtestBeanListFromJson=g

6、son.fromJson(beanListToJson,type);8.System.out.println(testBeanListFromJson);9.//prints[TestBean@1ea5671[id=id,name=name,birthday=]]java.lang.reflect.Typetype=newcom.google.gson.reflect.TypeToken>(){}.getType();StringbeanListToJson=gson.toJson(testBeanList,type);Syst

7、em.out.println(beanListToJson);//prints[{"id":"id","name":"name"}]ListtestBeanListFromJson=gson.fromJson(beanListToJson,type);System.out.println(testBeanListFromJson);//prints[TestBean@1ea5671[id=id,name=name,birthday=]]map等其他集合类型同上3.Date类型转化先写工具类Java代码1.i

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。