简体   繁体   中英

Retrieve Sparql query response in json format

I am using sparql-client from https://github.com/thomasfr/node-sparql-client . I wanted to know if there is a way to retrieve the query results in json format by giving some parameters?

My endpoint is an openrdf-sesame repository.

Currently, my response is as below:

<?xml version='1.0' encoding='UTF-8'?>
<sparql xmlns='http://www.w3.org/2005/sparql-results#'>
 .....
</sparql>

I used var r = JSON.stringify(results). But r.results show undefined. 在此处输入图片说明 Thanks !

Ah, how about this: According to this forum thread

You [have] to query the server directly as in the url below.

 http://localhost:8080/openrdf-sesame/repositories/memory?query=SELECT+*+WHERE+{‌​?s+?p+?o}&Accept=application/sparql-results%2Bjson 

The SparqlClient constructor looks like it takes two arguments: the endpoint and some options. It looks like you should be able to specify the Accept parameter application/sparql-results+json using that options argument. My ECMAScript is a bit rusty, but I think it'd be something like this:

var endpoint = 'http://example.org/sparql';
var client = new SparqlClient(endpoint, {Accept: 'application/sparql-results+json'});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM