
top.jfunc.json.impl.JSONObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Json-Gson Show documentation
Show all versions of Json-Gson Show documentation
common json interface implements by Gson
The newest version!
package top.jfunc.json.impl;
import top.jfunc.json.Json;
import top.jfunc.json.JsonArray;
import top.jfunc.json.JsonObject;
import com.google.gson.Gson;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author xiongshiyan at 2018/6/10
*/
public class JSONObject extends BaseMapJSONObject {
public JSONObject(Map map){
super(map);
}
public JSONObject(){
}
public JSONObject(String jsonString){
super(jsonString);
}
@Override
protected Map str2Map(String jsonString) {
return new Gson().fromJson(jsonString, Map.class);
}
@Override
public JsonObject parse(String jsonString) {
this.map = new Gson().fromJson(jsonString, Map.class);
return this;
}
@Override
public String serialize(Object javaBean) {
return new Gson().toJson(javaBean);
}
@Override
public T deserialize(String jsonString, Class clazz) {
return new Gson().fromJson(jsonString , clazz);
}
@Override
public JsonObject getJsonObject(String key) {
assertKey(key);
//这里不能使用getJSONObject,因为每一种Json实现不一样,给出的JsonObject类型是不一致的。
//这里就是各种JsonObject不能混用的原因
Object temp = this.map.get(key);
Object t = checkNullValue(key, temp);
if(t instanceof Map){
return new JSONObject((Map) t);
}
return (JsonObject) t;
}
@Override
public JsonArray getJsonArray(String key) {
assertKey(key);
//这里不能使用getJSONObject,因为每一种Json实现不一样,给出的JsonObject类型是不一致的。
//这里就是各种JsonObject不能混用的原因
Object temp = this.map.get(key);
Object t = checkNullValue(key, temp);
if(t instanceof List){
return new JSONArray((List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy