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 }
  • 相关阅读:
    Javascript 对象(object)合并 转
    数据库连接池设置
    约瑟夫问题
    链表中环入口节点
    Spring整合Mybatis
    Spring中事务管理
    Spring中对象和属性的注入方式
    把数组排成最小的数
    Spring之IOC
    Spring之AOP
  • 原文地址:https://www.cnblogs.com/DreamDrive/p/5779007.html
Copyright © 2011-2022 走看看