public class GsonUtils extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static Object |
fromJsonString(String json)
Returns the JSON object as a plain java object.
|
static <T> T |
fromJsonString(String json,
Type typeOfT)
Returns the JSON object as a plain java object by the specified type.
|
static <T> T |
fromMap(Map<String,Object> map,
Class<T> type)
Returns the JSON object as a plain java object by the specified type.
|
static boolean |
isJsonArray(String jsonStringArray)
Checks if the provided String is a representation of a JSON array.
|
static boolean |
isJsonObject(String jsonStringObject)
Checks if the provided String is a representation of a JSON object.
|
static com.google.gson.JsonElement |
jsonElementFrom(String jsonString)
Returns a jsonElement from a String representation of a JSON object.
|
static com.google.gson.JsonArray |
toJsonArray(String jsonStringArray)
Returns a JsonArray object from a String representation of a JSON array
object.
|
static com.google.gson.JsonElement |
toJsonElement(String jsonStringElement) |
static com.google.gson.JsonObject |
toJsonObject(String jsonStringObject)
Returns a JsonObject object from a String representation of a JSON
object.
|
static String |
toJsonString(Object object)
Returns the JSON String representation of an object.
|
static String |
toJsonString(Object object,
Type typeOfT)
Returns the JSON String representation of an object.
|
static Map<String,Object> |
toMap(Object object)
Returns the JSON object as a plain java object by the specified type.
|
public static String toJsonString(Object object)
object - an arbitrary object.public static String toJsonString(Object object, Type typeOfT)
object - an arbitrary object.typeOfT - the type of the desired arbitrary object.public static Object fromJsonString(String json)
json - a JSON String representation of a JSON object.public static <T> T fromJsonString(String json, Type typeOfT)
json - a JSON String representation of a JSON object.typeOfT - the type of the desired object.public static <T> T fromMap(Map<String,Object> map, Class<T> type)
map - a Map representation of an object.type - the type of the desired object.public static Map<String,Object> toMap(Object object)
public static com.google.gson.JsonObject toJsonObject(String jsonStringObject) throws com.google.gson.JsonSyntaxException, IllegalStateException
jsonStringObject - a String representation of a JSON object.com.google.gson.JsonSyntaxException - if JSON is not a valid representation for an object of type.IllegalStateException - if the element is of another type.public static com.google.gson.JsonArray toJsonArray(String jsonStringArray) throws com.google.gson.JsonSyntaxException, IllegalStateException
jsonStringArray - a String representation of a JSON array object.com.google.gson.JsonSyntaxException - if JSON is not a valid representation for an object of type.IllegalStateException - if the element is of another type.public static com.google.gson.JsonElement toJsonElement(String jsonStringElement) throws com.google.gson.JsonSyntaxException, IllegalStateException
com.google.gson.JsonSyntaxExceptionIllegalStateExceptionpublic static com.google.gson.JsonElement jsonElementFrom(String jsonString)
jsonString - a String representation of a JSON object.public static boolean isJsonObject(String jsonStringObject)
jsonStringObject - a possible String representation of a JSON object.public static boolean isJsonArray(String jsonStringArray)
jsonStringArray - a possible String representation of a JSON array.Copyright © 2021. All rights reserved.