zoukankan      html  css  js  c++  java
  • Gson处理

    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;
        }
        
        
    }
  • 相关阅读:
    元素定位8种方法
    excel做数据驱动
    selenium colse()与quit()方法的区别
    flask 获取request参数的几种形式
    hdu1272
    土地征用
    任务安排
    征途
    锯木厂选址
    特别行动队
  • 原文地址:https://www.cnblogs.com/ahwu/p/4512045.html
Copyright © 2011-2022 走看看