星空网 > 软件开发 > Java

Json Utils

import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;
import net.sf.json.
/**
 * 处理json数据格式的工具类
 */
public class JsonUtil {
    /**
     * 将数组转换成String类型的JSON数据格式
     *
     * @param objects
     * @return
     */
    public static String array2json(Object[] objects){
        
        JSONArray jsonArray = JSONArray.fromObject(objects);
        return jsonArray.toString();
        
    }
    
    /**
     * 将list集合转换成String类型的JSON数据格式
     *
     * @param list
     * @return
     */
    public static String list2json(List list){
        
        JSONArray jsonArray = JSONArray.fromObject(list);
        return jsonArray.toString();
        
    }
    
    /**
     * 将map集合转换成String类型的JSON数据格式
     *
     * @param map
     * @return
     */
    public static String map2json(Map map){
        
        JSONObject jsonObject = JSONObject.fromObject(map);
        return jsonObject.toString();
        
    }
    
    /**
     * 将Object对象转换成String类型的JSON数据格式
     *
     * @param object
     * @return
     */
    public static String object2json(Object object){
        
        JSONObject jsonObject = JSONObject.fromObject(object);
        return jsonObject.toString();
        
    }
    
    /**
     * 将     *
     * @param      * @return
     */
    public static String         
        JSONArray jsonArray = (JSONArray) new         return jsonArray.toString();
        
    }
    
    /**
      * 除去不想生成的字段(特别适合去掉级联的对象)
      *
      * @param excludes
      * @return
    */
    public static JsonConfig configJson(String[] excludes) {
        JsonConfig jsonConfig = new JsonConfig();
        jsonConfig.setExcludes(excludes);
        jsonConfig.setIgnoreDefaultExcludes(true);
        jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
        return jsonConfig;
    }
    
}




原标题:Json Utils

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

韩国到中国快递专线:https://www.goluckyvip.com/tag/33702.html
韩国电商开店:https://www.goluckyvip.com/tag/33703.html
韩国电商开店费用:https://www.goluckyvip.com/tag/33704.html
韩国电商开店流程:https://www.goluckyvip.com/tag/33705.html
韩国电商入驻:https://www.goluckyvip.com/tag/33706.html
韩国儿童节:https://www.goluckyvip.com/tag/33707.html
探讨内地人开设香港账户的可行性 :https://www.kjdsnews.com/a/1836442.html
在古巴做游轮 古巴旅游项目:https://www.vstour.cn/a/363194.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流