cq.json.JsonObject Maven / Gradle / Ivy
The newest version!
package cq.json;
import cq.json.util.StringUtil;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
/**
* JSON对象
*
* @version 1.0.0
*/
public class JsonObject {
private Map jsonObject = new HashMap<>();
public void add(String key, Object value) {
jsonObject.put(key, value);
}
public Object get(String key) {
return jsonObject.get(key);
}
public Map getJsonObject() {
return jsonObject;
}
public Integer getInteger(String key) {
return getValue(get(key), Integer.class);
}
public Byte getByte(String key) {
return getValue(get(key), Byte.class);
}
public Short getShort(String key) {
return getValue(get(key), Short.class);
}
public Long getLong(String key) {
return getValue(get(key), Long.class);
}
public Float getFloat(String key) {
return getValue(get(key), Float.class);
}
public Double getDouble(String key) {
return getValue(get(key), Double.class);
}
public Character getCharacter(String key) {
return getValue(get(key), Character.class);
}
public BigDecimal getBigDecimal(String key) {
return getValue(get(key), BigDecimal.class);
}
public Boolean getBoolean(String key) {
return getValue(get(key), Boolean.class);
}
public String getString(String key) {
return get(key) + "";
}
public JsonObject getJsonObject(String key) {
if (get(key) instanceof JsonObject){
return (JsonObject)get(key);
}
return null;
}
public JsonArray getJsonArray(String key) {
if (get(key) instanceof JsonArray){
return (JsonArray) get(key);
}
return null;
}
private T getValue(Object obj, Class clazz) {
if (obj instanceof String) {
return (T) StringUtil.str2obj((String) obj, clazz);
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy