protected function EasyRdf_Sparql_Result::parseJson in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Result.php \EasyRdf_Sparql_Result::parseJson()
Parse a SPARQL result in the JSON format into the object.
@ignore
1 call to EasyRdf_Sparql_Result::parseJson()
- EasyRdf_Sparql_Result::__construct in vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Sparql/ Result.php - Create a new SPARQL Result object
File
- vendor/
easyrdf/ easyrdf/ lib/ EasyRdf/ Sparql/ Result.php, line 341
Class
- EasyRdf_Sparql_Result
- Class for returned for SPARQL SELECT and ASK query responses.
Code
protected function parseJson($data) {
// Decode JSON to an array
$data = json_decode($data, true);
if (isset($data['boolean'])) {
$this->type = 'boolean';
$this->boolean = $data['boolean'];
}
elseif (isset($data['results'])) {
$this->type = 'bindings';
if (isset($data['head']['vars'])) {
$this->fields = $data['head']['vars'];
}
foreach ($data['results']['bindings'] as $row) {
$t = new stdClass();
foreach ($row as $key => $value) {
$t->{$key} = $this
->newTerm($value);
}
$this[] = $t;
}
}
else {
throw new EasyRdf_Exception("Failed to parse SPARQL JSON Query Results format");
}
}