30 lines
783 B
Java
30 lines
783 B
Java
package com.aoleyun.os.uiuiutils;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonParser;
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
import java.lang.reflect.Type;
|
|
|
|
|
|
public class GsonUtils {
|
|
public static JsonObject getJsonObject(String jsonString) {
|
|
JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
|
|
return jsonObject;
|
|
}
|
|
|
|
// TODO: 2022/3/31 暂时没有实现
|
|
public static <E> E getJsonFromType(String jsonString) {
|
|
Gson gson = new Gson();
|
|
Type Type = new TypeToken<E>() {
|
|
}.getType();
|
|
E e = gson.fromJson(jsonString, Type);
|
|
return e;
|
|
}
|
|
|
|
public static String toJsonString(Object o) {
|
|
return new Gson().toJson(o);
|
|
}
|
|
}
|