You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					92 lines
				
				2.6 KiB
			
		
		
			
		
	
	
					92 lines
				
				2.6 KiB
			| 
								 
											2 years ago
										 
									 | 
							
								package com.ynxbd.common.helper.common;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import com.alibaba.fastjson.JSON;
							 | 
						||
| 
								 | 
							
								import com.alibaba.fastjson.JSONArray;
							 | 
						||
| 
								 | 
							
								import com.alibaba.fastjson.JSONObject;
							 | 
						||
| 
								 | 
							
								import com.alibaba.fastjson.TypeReference;
							 | 
						||
| 
								 | 
							
								import com.ynxbd.common.bean.xbd.MRHistory;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import java.util.List;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * FastJson操作类
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								public class JsonHelper {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public static String toJsonString(Object data) {
							 | 
						||
| 
								 | 
							
								        return JSON.toJSONString(data);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public static JSONObject parseObject(String data) {
							 | 
						||
| 
								 | 
							
								        return JSON.parseObject(data);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public static <T> T parseObject(String data, Class<T> clazz) {
							 | 
						||
| 
								 | 
							
								        return JSON.parseObject(data, clazz);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public static JSONArray parseArray(String data) {
							 | 
						||
| 
								 | 
							
								        return JSON.parseArray(data);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public static <T> List<T> parseArray(String data, Class<T> clazz) {
							 | 
						||
| 
								 | 
							
								        return JSON.parseArray(data, clazz);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * fastJson反序列化Bean
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param json  json
							 | 
						||
| 
								 | 
							
								     * @param clazz 类型
							 | 
						||
| 
								 | 
							
								     * @return bean
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static <T> T decodeBean(Object json, Class<T> clazz) {
							 | 
						||
| 
								 | 
							
								        return decodeBean(toJsonString(json), clazz);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * fastJson反序列化Bean
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param json  json
							 | 
						||
| 
								 | 
							
								     * @param clazz 类型
							 | 
						||
| 
								 | 
							
								     * @return bean
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static <T> T decodeBean(String json, Class<T> clazz) {
							 | 
						||
| 
								 | 
							
								        return parseObject(json, clazz);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * fastJson反序列化List
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param json  json
							 | 
						||
| 
								 | 
							
								     * @param clazz 类型
							 | 
						||
| 
								 | 
							
								     * @return List<T>
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static <T> List<T> decodeList(String json, Class<T> clazz) {
							 | 
						||
| 
								 | 
							
								        return decode(json, new TypeReference<List<T>>(clazz) {
							 | 
						||
| 
								 | 
							
								        });
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * fastJson反序列化
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param json          json
							 | 
						||
| 
								 | 
							
								     * @param typeReference 类型
							 | 
						||
| 
								 | 
							
								     * @return 反序列化后的值
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    private static <T> T decode(String json, TypeReference<T> typeReference) {
							 | 
						||
| 
								 | 
							
								        try {
							 | 
						||
| 
								 | 
							
								            return JSON.parseObject(json, typeReference);
							 | 
						||
| 
								 | 
							
								        } catch (Exception e) {
							 | 
						||
| 
								 | 
							
								            e.printStackTrace();
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        return null;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public static void main(String[] args) {
							 | 
						||
| 
								 | 
							
								        List<MRHistory> test = parseArray("[{\"Ba_Borrow_Apply_Name\":\"杨木苗\",\"Out_Hosp_Time\":\"2013-08-0115:58:00\",\"BA_Borrow_isPrint\":false,\"Zynum\":\"1049499\",\"BA_Borrow_isPay\":false,\"In_Hosp_Time\":\"2012-08-1015:30:00\",\"Dx\":\"精神分裂症\",\"Ba_Borrow_Useto_Name\":\"律师\",\"BA_Borrow_OperDate\":\"2023-06-2015:55:28\",\"Ba_Borrow_Phone\":\"1\",\"Bano\":\"1049499\",\"Ba_Borrow_Getway\":0,\"Ba_Borrow_Address\":\"1\"}]", MRHistory.class);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |