|
|
|
package com.fanruan.api.json;
|
|
|
|
|
|
|
|
import com.fr.json.JSON;
|
|
|
|
import com.fr.json.JSONArray;
|
|
|
|
import com.fr.json.JSONFactory;
|
|
|
|
import com.fr.json.JSONObject;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建JSON对象相关的工具类
|
|
|
|
*/
|
|
|
|
public class JSONKit {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建一个空的JSON对象
|
|
|
|
*
|
|
|
|
* @return JSON对象
|
|
|
|
*/
|
|
|
|
public static JSONObject create() {
|
|
|
|
return JSONFactory.createJSON(JSON.OBJECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据文本创建一个JSONObject对象
|
|
|
|
*
|
|
|
|
* @param text 文本
|
|
|
|
* @return JSON对象
|
|
|
|
*/
|
|
|
|
public static JSONObject create(String text) {
|
|
|
|
return JSONFactory.createJSON(JSON.OBJECT, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据一个字典创建一个JSON对象
|
|
|
|
*
|
|
|
|
* @param map 字典
|
|
|
|
* @return JSON对象
|
|
|
|
*/
|
|
|
|
public static JSONObject create(Map<String, Object> map) {
|
|
|
|
return JSONFactory.createJSON(JSON.OBJECT, map);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 创建一个空的JSON数组
|
|
|
|
*
|
|
|
|
* @return JSON数组
|
|
|
|
*/
|
|
|
|
public static JSONArray createJSONArray() {
|
|
|
|
return JSONFactory.createJSON(JSON.ARRAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据文本内容创建一个JSON数组
|
|
|
|
*
|
|
|
|
* @param text 文本
|
|
|
|
* @return JSON数组
|
|
|
|
*/
|
|
|
|
public static JSONArray createJSONArray(String text) {
|
|
|
|
return JSONFactory.createJSON(JSON.ARRAY, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据一个集合创建一个JSON数组
|
|
|
|
*
|
|
|
|
* @param collection 集合
|
|
|
|
* @return JSON数组
|
|
|
|
*/
|
|
|
|
public static JSONArray createJSONArray(Collection collection) {
|
|
|
|
return JSONFactory.createJSON(collection);
|
|
|
|
}
|
|
|
|
}
|