Hey i'm trying to make a web service and i'm using Jena distibution. At the moment i have created my model and its printing out in RDF/XML format. I want to get my data to a JSON file saved in my hard disk. How can i do that?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
org.openjena.riot.out.RDFJSONWriter
writes Talis-style RDF/JSON (i.e not JSON-LD).- Look for a JSON-LD writer (I think there are ones that read RDF and write JSON-LD)
- Use SPARQL JSON Results format
回答2:
Now the Jena RIOT readers/writers support also the RDF/JSON serialization; then you just need to do the following:
org.openjena.riot.RIOT.init(); //wires RIOT readers/writers into Jena
java.io.OutputStream os = null;
// Serialize over an outputStream
os = new java.io.ByteArrayOutputStream();
model.write(os, "RDF/JSON", relativeUriBase);