/**
* Creates a {@link JsonObject} from the given json string.
*
* @param jsonString the json string to parse
* @return the {@link JsonObject} received while parsing the given json string
* @throws JsonParsingFailedException if any exception occurred at runtime
*/
public static JsonObject createJsonObjectFromString(final String jsonString) throws JsonParsingFailedException {
InputStream stream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8));
Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
JsonObject readJsonObject = null;
try {
readJsonObject = new Gson().fromJson(reader, JsonObject.class);
} catch (JsonSyntaxException jsonSyntaxException) {
throw new JsonParsingFailedException(jsonSyntaxException);
} catch (JsonIOException jsonIoException) {
throw new JsonParsingFailedException(jsonIoException);
}
return readJsonObject;
}
JsonUtils.java 文件源码
java
阅读 35
收藏 0
点赞 0
评论 0
项目:jpl-framework
作者:
评论列表
文章目录