本文整理了Java中org.apache.jena.atlas.json.JSON.parseAny()
方法的一些代码示例,展示了JSON.parseAny()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSON.parseAny()
方法的具体详情如下:
包路径:org.apache.jena.atlas.json.JSON
类名称:JSON
方法名:parseAny
[英]Parse any JSON value, not just an object, from an input stream
[中]解析输入流中的任何JSON值,而不仅仅是对象
代码示例来源:origin: apache/jena
/** Read any JSON value, not just an object, from a file */
public static JsonValue readAny(String filename) {
try {
try (InputStream in = IO.openFileEx(filename)) {
return JSON.parseAny(in) ;
}
}
catch (FileNotFoundException ex) {
throw new RuntimeException("File not found: " + filename, ex) ;
}
catch (IOException ex) {
IO.exception("IOException: " + filename, ex) ;
return null ;
}
}
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-arq
/** Read any JSON value, not just an object, from a file */
public static JsonValue readAny(String filename)
{
try
{
InputStream in = IO.openFileEx(filename) ;
try { return JSON.parseAny(in) ; } finally { in.close() ; }
}
catch (FileNotFoundException ex)
{
throw new RuntimeException("File not found: "+filename, ex) ;
}
catch (IOException ex)
{
IO.exception("IOException: "+filename, ex);
return null ;
}
}
代码示例来源:origin: apache/jena
/** Round trip string->json->string->json, compare two JOSN steps */
public static void read(String string)
{
JsonValue v = JSON.parseAny(string) ;
writeRead(v) ;
}
代码示例来源:origin: apache/jena
/** Read-compare */
public static void read(String string, JsonValue expected)
{
JsonValue v = JSON.parseAny(string) ;
assertEquals(expected, v) ;
}
代码示例来源:origin: apache/jena
/** Round trip json->string->json */
public static void writeRead(JsonValue v)
{
String str2 = v.toString();
JsonValue v2 = JSON.parseAny(str2) ;
assertEquals(v, v2) ;
}
代码示例来源:origin: org.seaborne.rdf-delta/rdf-delta-client
try {
String s = IO.readWholeFileAsUTF8(x) ;
return JSON.parseAny(s) ;
} catch (IOException ex) { throw IOX.exception(ex); }
return JSON.parseAny(x) ;
} catch (HttpException ex) {
if ( HttpSC.BAD_REQUEST_400 == ex.getResponseCode() ) {
代码示例来源:origin: apache/jena
@Test public void jsonAPI_03() {
JsonValue jv1 = JSON.parseAny("2") ;
JsonValue jv2 = JSON.copy(jv1);
assertSame(jv1, jv2);
}
}
代码示例来源:origin: apache/jena
@Test
public void jsonBuildObject_02() {
JsonValue x = JSON.parseAny("{ key1: 'value1', key2: 'value2' }") ;
JsonObject obj = JsonBuilder.buildObject(b->{
b.pair("key1", "value1")
.pair("key2", "value2");
});
assertEquals(x, obj);
}
}
代码示例来源:origin: apache/jena
@Override
public JsonArray execJson()
{
checkNotClosed();
HttpQuery httpQuery = makeHttpQuery();
httpQuery.setAccept(WebContent.contentTypeJSON);
JsonArray result = new JsonArray();
try(InputStream in = httpQuery.exec()) {
JsonValue v = JSON.parseAny(in);
if ( ! v.isArray() )
throw new QueryExecException("Return from a JSON query isn't an array");
result = v.getAsArray();
} catch (IOException e) { IO.exception(e); }
finally { this.close(); }
return result;
}
代码示例来源:origin: apache/jena
@Test public void jsonBuild03() {
JsonValue x = JSON.parseAny("[ ]") ;
JsonBuilder builder = new JsonBuilder() ;
builder.startArray() ;
builder.finishArray() ;
JsonValue v = builder.build() ;
assertEquals(x,v) ;
}
代码示例来源:origin: apache/jena
private void test(String queryString, String jsonExpected) {
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
DatasetGraph dsg = new DatasetGraphZero();
Dataset ds = DatasetFactory.wrap(dsg);
try ( QueryExecution qExec = QueryExecutionFactory.create(query, ds) ) {
JsonValue jvGot = qExec.execJson() ;
JsonValue jvExpected = JSON.parseAny(jsonExpected) ;
assertEquals(jvExpected, jvGot);
}
}
}
代码示例来源:origin: apache/jena
@Test public void jsonBuild01() {
JsonValue x = JSON.parseAny("{ }") ;
JsonBuilder builder = new JsonBuilder() ;
builder.startObject("A") ;
builder.finishObject("A") ;
JsonValue v = builder.build() ;
assertEquals(x,v) ;
}
代码示例来源:origin: apache/jena
@Test public void jsonBuild06() {
JsonValue x = JSON.parseAny("{ a: 'B'}") ;
JsonBuilder builder = new JsonBuilder() ;
builder.startObject().pair("a", "B").finishObject() ;
JsonValue v = builder.build() ;
assertEquals(x,v) ;
}
代码示例来源:origin: apache/jena
@Test public void jsonBuild07() {
JsonValue x = JSON.parseAny("{ a: 123}") ;
JsonBuilder builder = new JsonBuilder() ;
builder.startObject().pair("a", 123).finishObject() ;
JsonValue v = builder.build() ;
assertEquals(x,v) ;
}
代码示例来源:origin: apache/jena
@Test public void jsonBuild08() {
JsonValue x = JSON.parseAny("{ a: true}") ;
JsonBuilder builder = new JsonBuilder() ;
JsonValue jv = new JsonBoolean(true);
builder.startObject().pair("a", jv).finishObject() ;
JsonValue v = builder.build() ;
assertEquals(x,v) ;
}
代码示例来源:origin: apache/jena
@Test public void jsonBuild02() {
JsonValue x = JSON.parseAny("{ a: 'A', b:'B'}") ;
JsonBuilder builder = new JsonBuilder() ;
builder.startObject("Obj1") ;
builder.key("a").value("A") ;
builder.key("b").value("B") ;
builder.finishObject("Obj1") ;
JsonValue v = builder.build() ;
assertEquals(x,v) ;
}
代码示例来源:origin: apache/jena
@Test public void jsonBuild05() {
JsonValue x = JSON.parseAny("[ { a: 'B'} , 56]") ;
JsonBuilder builder = new JsonBuilder() ;
builder.startArray() ;
builder.startObject().key("a").value("B").finishObject() ;
builder.value(56) ;
builder.finishArray() ;
JsonValue v = builder.build() ;
assertEquals(x,v) ;
}
代码示例来源:origin: apache/jena
@Test public void jsonBuild04() {
JsonValue x = JSON.parseAny("{ a: [1], b:'B'}") ;
JsonBuilder builder = new JsonBuilder() ;
builder.startObject() ;
builder.key("a").startArray().value(1).finishArray() ;
builder.key("b").value("B") ;
builder.finishObject() ;
JsonValue v = builder.build() ;
assertEquals(x,v) ;
}
内容来源于网络,如有侵权,请联系作者删除!