public class GsonTools {

    public GsonTools(){}

    public static <T> T getPerson(String jsonString,Class<T> cls){
T t = null;
try {
Gson gson = new Gson();
t = gson.fromJson(jsonString, cls);
} catch (Exception e) {
e.printStackTrace();
}
return t;
} public static <T> List<T> getPersons(String jsonString,Class<T> cls){
List<T> list = new ArrayList<T>();
try {
Gson gson = new Gson();
list = gson.fromJson(jsonString, new TypeToken<List<T>>(){}.getType());
} catch (Exception e) {
e.printStackTrace();
}
return list;
} public static List<String> getList(String jsonString){
List<String> list = new ArrayList<String>(); try {
Gson gson = new Gson();
list = gson.fromJson(jsonString, new TypeToken<List<String>>(){}.getType());
} catch (Exception e) {
e.printStackTrace();
}
return list;
} public static List<Map<String, Object>> listKeyMaps(String jsonString){
List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
try {
Gson gson = new Gson();
list = gson.fromJson(jsonString, new TypeToken<List<Map<String, Object>>>(){}.getType());
} catch (Exception e) {
e.printStackTrace();
}
return list;
} }

Gson处理的更多相关文章

  1. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  2. Gson将字符串转换成JsonObject和JsonArray

    以下均利用Gson来处理: 1.将bean转换成Json字符串: public static String beanToJSONString(Object bean) { return new Gso ...

  3. Gson解析纯Json数组

    [ { "type": "123", "value": 123 }, { "type": "234" ...

  4. 【Gson】互相转化

    Gson 是 Google 提供的用来在 Java 对象和 JSON 数据之间进行映射的 Java 类库.可以将一个 JSON 字符串转成一个 Java 对象,或者反过来. 对象转为字符串 Strin ...

  5. Android Gson解析

    目前解析json有三种工具:org.json(Java常用的解析),fastjson(阿里巴巴工程师开发的),Gson(Google官网出的),解析速度最快的是Gson,下载地址:https://co ...

  6. Android总结之json解析(FastJson Gson 对比)

    前言: 最近为了统一项目中使用的框架,发现项目中用到了两种json解析框架,他们就是当今非常主流的json解析框架:google的Gson 和阿里巴巴的FastJson,为了废除其中一个所以来个性能和 ...

  7. gson笔记 解析json数据

    gson中负责json数据解析的类是JsonReader. Json格式有两种结构,一种是对象(键值对的组合,无序),另外一种是数组(值的有序集合). 因此针对这两种格式,JsonReader提供了不 ...

  8. Android Gson的使用总结

    1.概念 Gson是谷歌发布的一个json解析框架 2.如何获取 github:https://github.com/google/gson android studio使用 compile 'com ...

  9. Android JSON、GSON、FastJson的封装与解析

    声明: 1.本帖只提供代码,不深入讲解原理.如果读者想要深入了解,那就不要在这个帖子上浪费时间了 2.客户端用的是Google官方的Volley访问服务器,具体了解Volley请戳 这里 3.本帖三种 ...

  10. Java Gson 简要笔记

    Gson是Google开发的Java比较好用的 Json工具. 使用挺简单,假设有个类: class Runner { int attr; String name; public Runner(int ...

随机推荐

  1. 【html5】常见标签使用说明(持续更新)

    说明: 所谓常见,是指我在优秀网页源码中见到的. 1.viewport 我见到的时候是这样: <meta name="viewport" content="widt ...

  2. Visual Studio 如何恢复默认设置

    我们在使用 Visual Studio 的时候,常常有一些窗口不见了又弄不回来的情况,如何恢复默认设置呢? 1.点击“开始-->程序-->Microsoft Visual Studio20 ...

  3. apache开启.htaccess

    1 . 如何让的本地APACHE开启.htaccess 如何让的本地APACHE开启.htaccess呢?其实只要简朴修改一下apache的httpd.conf设置就让APACHE.htaccess了 ...

  4. ASP.NET 成功执行Update 的 ExecuteNonQuery() 返回值大于0,但是查看数据库却没有改变

    //真实姓名保存 $("#TrueNameSaveBtn").click(function () { if ($("#TrueNameSaveText").va ...

  5. linux 查看剩余内存数

    返回的是kb的数值 cat /proc/meminfo | grep MemFree | cut -d ":" -f2 | sed -e 's/\(^ *\)//' -e 's/\ ...

  6. Gridview布局界面练习Base Adapter

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZcAAAJVCAIAAACdzC94AAAgAElEQVR4nOy953Ij2bGuLTVJmFrelf

  7. hdu 1052 (greedy algorithm) 分类: hdoj 2015-06-18 16:49 35人阅读 评论(0) 收藏

    thanks to http://acm.hdu.edu.cn/discuss/problem/post/reply.php?action=support&postid=19638&m ...

  8. Unparsed aapt error(s)! Check the console for output解决方法

    在Eclipse平台进行Android 应用开发时,编辑,修改或增删 res/下资源文件时有时会遇到如下错误提示:“Unparsed  aapt error(s)! Check the console ...

  9. Jquery EasyUI Tree .net实例

    图片: 针对tree: 数据库: CREATE TABLE [dbo].[SystemModel]( [Id] [,) NOT NULL, [Name] [nvarchar]() NULL, [Fat ...

  10. Mybatis-动态 SQL

    MyBatis 的强大特性之一便是它的动态 SQL. 如果你有使用 JDBC 或其他类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句有多么痛苦.拼接的时候要确保不能忘了必要的空格,还要注意省 ...