zoukankan      html  css  js  c++  java
  • 使用json-lib-*.jar的JSON解析工具类

    使用json-lib-2.4-jdk15.jar

    JSON工具类:

     1 import java.util.List;
     2 
     3 import net.sf.json.JSONArray;
     4 import net.sf.json.JSONObject;
     5 
     6 public class JsonUtil {
     7     
     8      public static Object getObjectFromJsonString(String jsonString, Class<?> pojoCalss) {
     9 
    10          JSONObject jsonObject = JSONObject.fromObject(jsonString);  
    11          Object pojo = JSONObject.toBean(jsonObject, pojoCalss);  
    12          return pojo;  
    13      }
    14      
    15      public static String getJsonStringFromObject(Object javaObj) {  
    16          JSONObject json = JSONObject.fromObject(javaObj);  
    17          return json.toString();  
    18      }  
    19      
    20      public static Object[] getObjectArrayFromJsonString(String jsonString) {  
    21          JSONArray jsonArray = JSONArray.fromObject(jsonString);  
    22          return jsonArray.toArray();  
    23      }  
    24      
    25      public static String getJsonStringFromList(List<?> list) {  
    26          JSONArray jsonArray = JSONArray.fromObject(list);
    27          return jsonArray.toString();  
    28      } 
    29 
    30 }
  • 相关阅读:
    [NOIp2016] 天天爱跑步
    状压DP小拼盘
    DP × KMP
    KMP算法 详解+模板
    [NOI2014] 起床困难综合症
    [洛谷P3391] 文艺平衡树 (Splay模板)
    START
    【C】单链表的实现
    【数据结构】动态顺序表
    C语言实现扫雷程序
  • 原文地址:https://www.cnblogs.com/DreamDrive/p/5779007.html
Copyright © 2011-2022 走看看