src/com/my/sociality/utils/JsonUtil.java

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package com.my.sociality.utils;

import java.io.IOException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;


import net.sf.ezmorph.MorphException;
import net.sf.ezmorph.MorpherRegistry;
import net.sf.ezmorph.object.AbstractObjectMorpher;
import net.sf.ezmorph.object.DateMorpher;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.JSONUtils;

public class JsonUtil {

	private static final String[] DATE_FORMAT = { "yyyy-MM-dd HH:mm:ss" }; 
	
    public static String toJson(Object o) {
    	
    	JsonConfig jsonConfig = new JsonConfig();  
		jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor());
		jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class, new DateJsonValueProcessor());
    	System.out.println(JSONObject.fromObject(o));
		System.out.println(JSONObject.fromObject(o, jsonConfig).toString());
    	try {
			return JSONObject.fromObject(o, jsonConfig).toString();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
    }
    /***
     * 
    * @Title: toJsonArray 
    * @Description:把一个List转换为json字符串
    * @param @param o
    * @param @return    设定文件 
    * @return String    返回类型 
    * @Author 
    * @throws
     */
    public static String toJsonArray(Object o) {
    	
    	JsonConfig jsonConfig = new JsonConfig();  
		jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor());
		jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class, new DateJsonValueProcessor());
    	
    	try {
			return JSONArray.fromObject(o, jsonConfig).toString();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
    }
	@SuppressWarnings("unchecked")
	public static <T> T toBean(String jsonStr, Class<T> clazz) {
		T returnValue = null;
		
后面还有 121 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。