使用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 }

 

相关文章:

  • 2022-12-23
  • 2021-05-17
  • 2022-03-13
  • 2022-12-23
  • 2022-12-23
  • 2019-10-25
  • 2022-12-23
猜你喜欢
  • 2021-07-13
  • 2022-12-23
  • 2022-03-13
  • 2021-11-20
  • 2022-01-22
  • 2022-12-23
相关资源
相似解决方案