工具类--JsonUtils 数据解析
2016-08-22 14:09
411 查看
/*** * json工具解析类 */ public class JsonUtils { private static Gson gson = new Gson(); public static <T> T toBean(Class<T> type, String s) { if (s == null) { return null; } return gson.fromJson(s, type); } public static <T> T toBean(Type type, String s) { if (s == null) { return null; } return gson.fromJson(s, type); } public static <T> List<T> getList(Class<T[]> type, String s) { if (s == null) return null; List<T> results = new ArrayList<T>(); try { T[] _next = toBean(type, s); if (_next != null) Collections.addAll(results, _next); } catch (Exception e) { return null; } return results; } public static <T> T toBean(Class<T> type, Reader reader) throws IOException { TypeAdapter<T> adapter = gson.getAdapter(type); JsonReader jsonReader = gson.newJsonReader(reader); try { return adapter.read(jsonReader); } finally { jsonReader.close(); } } }
相关文章推荐
- 用于解析Json数据的HttpUtils工具类
- android解析JSON,XML数据的请求网络工具类
- 解析服务器返回的Json 数据的工具类
- java工具类开发之json工具类JsonUtils和写数据回页面工具类ResponseUtils
- 关于C#使用工具类解析JSON数据以及将类JSON化
- Android开发中json数据解析工具类
- Java解析POST提交的json数据工具类
- 【工具类系列】浏览器解析JSON数据插件,解决数据加密乱码,以及JSON格式化问题
- Utils包下的NetWorkUtils),解析json数据通用
- Android开发中json数据解析工具类
- 用fastjson框架解析Json数据工具类
- JsonUtils ~~fastJson解析工具类
- JQuery 解析多维的Json数据格式
- 解析JSON格式的数据时,有的字段为空值
- [转]flex中使用corelib ActionScript 3 Library sdk包解析json数据
- JavaScript 解析 JSON 数据
- PHP JSON 数据解析代码
- 前台利用javascript解析Json数据,生成编码折线
- php 无限级数据JSON格式及JS解析
- JSON 体验JSON (三)JSON 数据格式解析(转载)