如何将JENA ResultSet存储为JSON格式的字符串?我目前只能将ResultSet输出到System.out控制台,但我无法将其保存到java String。这是我所在的一个例子:
QueryExecution qexec = QueryExecutionFactory.sparqlService(endpoint, query);
ResultSet results = qexec.execSelect();
// the following prints out JSON in the System.out console:
ResultSetFormatter.outputAsJSON(System.out, results);
// but how do I save it as a String?
// ie.
String json = ResultSetFormatter.outputAsJSON(System.out, results);
// obviously that doesn't work, but how would one get the equivalent working version?
我希望能够将JSON变量发送到另一个方法来执行某些工作。
提前致谢!
答案 0 :(得分:6)
尝试写入SELECT ... WHERE ...
并将其中的字节转换为ByteArrayOutputStream
String