本文整理了Java中com.eclipsesource.json.Json.parse()
方法的一些代码示例,展示了Json.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.parse()
方法的具体详情如下:
包路径:com.eclipsesource.json.Json
类名称:Json
方法名:parse
[英]Reads the entire input from the given reader and parses it as JSON. The input must contain a valid JSON value, optionally padded with whitespace.
Characters are read in chunks into an input buffer. Hence, wrapping a reader in an additional BufferedReader
likely won't improve reading performance.
[中]从给定的读取器读取整个输入,并将其解析为JSON。输入必须包含有效的JSON值,可以选择填充空格。
字符分块读入输入缓冲区。因此,用额外的BufferedReader
包装读卡器可能不会提高阅读性能。
代码示例来源:origin: Vedenin/useful-java-links
public static void main(String[] args) throws IOException {
// convert Java to writer
JsonObject root = Json.object().add("message", "Hi").add(
"place", Json.object().add("name", "World!")
);
StringWriter writer = new StringWriter();
root.writeTo(writer);
String json = writer.toString();
System.out.println(json);
System.out.println();
// convert writer to Java
JsonObject obj = Json.parse(json).asObject();
String message = obj.get("message").asString();
String name = obj.get("place").asObject().get("name").asString();
System.out.println(message + " " + name);
}
}
代码示例来源:origin: ralfstx/minimal-json
@Override
public Object readFromString(String string) throws IOException {
return Json.parse(string);
}
代码示例来源:origin: ralfstx/minimal-json
@Override
public Object readFromReader(Reader reader) throws IOException {
return Json.parse(reader);
}
代码示例来源:origin: ralfstx/minimal-json
/**
* Reads a JSON value from the given string.
*
* @param text
* the string that contains the JSON value
* @return the JSON value that has been read
* @throws ParseException
* if the input is not valid JSON
* @deprecated Use {@link Json#parse(String)} instead
*/
@Deprecated
public static JsonValue readFrom(String text) {
return Json.parse(text);
}
代码示例来源:origin: ralfstx/minimal-json
/**
* Reads a JSON value from the given reader.
* <p>
* Characters are read in chunks and buffered internally, therefore wrapping an existing reader in
* an additional <code>BufferedReader</code> does <strong>not</strong> improve reading
* performance.
* </p>
*
* @param reader
* the reader to read the JSON value from
* @return the JSON value that has been read
* @throws IOException
* if an I/O error occurs in the reader
* @throws ParseException
* if the input is not valid JSON
* @deprecated Use {@link Json#parse(Reader)} instead
*/
@Deprecated
public static JsonValue readFrom(Reader reader) throws IOException {
return Json.parse(reader);
}
代码示例来源:origin: ralfstx/minimal-json
private void createJsonFile() throws IOException {
JsonObject caliperJson = Json.parse(readFromFile(resultsFile)).asObject();
String resultsJson = new CaliperResultsPreprocessor(caliperJson).getResults().toString();
writeToFile(resultsJson, resultsFile);
}
代码示例来源:origin: com.github.wnameless/json-flattener
/**
* Creates a JSON unflattener.
*
* @param jsonReader
* the JSON reader
* @throws IOException
* if jsonReader cannot be read
*/
public JsonUnflattener(Reader jsonReader) throws IOException {
root = Json.parse(jsonReader);
}
代码示例来源:origin: com.github.wnameless/json-flattener
/**
* Creates a JSON flattener.
*
* @param json
* the JSON string
*/
public JsonFlattener(String json) {
source = Json.parse(json);
}
代码示例来源:origin: com.github.wnameless/json-flattener
/**
* Creates a JSON flattener.
*
* @param jsonReader
* the JSON reader
* @throws IOException
* if jsonReader cannot be read
*/
public JsonFlattener(Reader jsonReader) throws IOException {
source = Json.parse(jsonReader);
}
代码示例来源:origin: wnameless/json-flattener
/**
* Creates a JSON flattener.
*
* @param json
* the JSON string
*/
public JsonFlattener(String json) {
source = Json.parse(json);
}
代码示例来源:origin: wnameless/json-flattener
/**
* Creates a JSON unflattener.
*
* @param json
* the JSON string
*/
public JsonUnflattener(String json) {
root = Json.parse(json);
}
代码示例来源:origin: wnameless/json-flattener
/**
* Creates a JSON unflattener.
*
* @param jsonReader
* the JSON reader
* @throws IOException
* if jsonReader cannot be read
*/
public JsonUnflattener(Reader jsonReader) throws IOException {
root = Json.parse(jsonReader);
}
代码示例来源:origin: io.thorntail/config-api-generator
public static Config fromJson(String filename) throws Exception {
return new Config(
Json.parse(
new FileReader(filename)
).asObject()
);
}
代码示例来源:origin: org.wildfly.swarm/config-api-generator
public static Config fromJson(String filename) throws Exception {
return new Config(
Json.parse(
new FileReader(filename)
).asObject()
);
}
代码示例来源:origin: org.eclipse.ditto/ditto-json
private static com.eclipsesource.json.JsonValue tryToRead(final String json) {
try {
return Json.parse(json);
} catch (final ParseException | StackOverflowError e) {
throw JsonParseException.newBuilder()
.message(MessageFormat.format("Failed to parse ''{0}''!", json))
.cause(e)
.build();
}
}
代码示例来源:origin: org.wildfly.swarm/fraction-list
@SuppressWarnings({"unchecked", "rawtypes"})
public FractionListParser(InputStream fractionListJson, InputStream packageSpecStream) throws IOException {
try (InputStreamReader reader = new InputStreamReader(fractionListJson)) {
Json.parse(reader).asArray().forEach(entry -> {
JsonObject fraction = entry.asObject();
FractionDescriptor fd = getFractionDescriptor(fraction);
addDependencies(fraction, fd);
});
}
packageSpecs.putAll((Map) PropertiesUtil.loadProperties(packageSpecStream));
}
代码示例来源:origin: io.thorntail/fraction-metadata
@SuppressWarnings({"unchecked", "rawtypes"})
public FractionListParser(InputStream fractionListJson) throws IOException {
try (InputStreamReader reader = new InputStreamReader(fractionListJson)) {
Json.parse(reader).asArray().forEach(entry -> {
JsonObject fraction = entry.asObject();
FractionDescriptor fd = getFractionDescriptor(fraction);
addDependencies(fraction, fd);
});
}
}
代码示例来源:origin: org.eclipse.ditto/ditto-json
private static com.eclipsesource.json.JsonArray tryToReadMinimalJsonArrayFrom(final String jsonString) {
try {
final com.eclipsesource.json.JsonValue parsedJsonString = Json.parse(jsonString);
return parsedJsonString.asArray();
} catch (final ParseException | UnsupportedOperationException | StackOverflowError e) {
throw JsonParseException.newBuilder()
.message("Failed to create JSON array from string!")
.cause(e)
.build();
}
}
代码示例来源:origin: org.eclipse.ditto/ditto-json
private static com.eclipsesource.json.JsonObject tryToReadJsonObjectFrom(final String jsonString) {
try {
final com.eclipsesource.json.JsonValue parsedJsonString = Json.parse(jsonString);
return parsedJsonString.asObject();
} catch (final ParseException | UnsupportedOperationException | StackOverflowError e) {
throw JsonParseException.newBuilder()
.message("Failed to create JSON object from string!")
.cause(e)
.build();
}
}
代码示例来源:origin: UniversaBlockchain/universa
@Test
public void testPreRequisites() throws Exception {
JsonObject object = Json.parse("{\"name\":\"test\"}").asObject();
String name = object.get("name").asString();
assertEquals("test", name);
}
内容来源于网络,如有侵权,请联系作者删除!