dimanche 1 février 2015

Parsing a neo4j JSON object in javascript


Vote count:

0




I am just playing around with Neo4j and trying to retrieve data from Neo4j in JSON format and then trying to parse it to try and get the values correctly.


I am calling a php code from my html,javascript client and the php is making a curl call to neo4j . The query is simple returning one node from neo4j which has one property to the node. The PHP code:



enter code here
<?php
header('Access-Control-Allow-Origin: *');`enter code here`
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
$data=array(
"query" =>"MATCH (a:LandMark {name:'Acharya College' })
RETURN a as ROUTE;",
);
$data=json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://localhost:7474/db/data/cypher/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_HTTPHEADER,array
('Accept: application/json; charset=UTF-8','Content-Type:
application/json',
'Content-Length: ' .
strlen($data),'X-Stream: true'));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
$result1 = curl_exec($curl);
echo json_encode($result1);
curl_close($curl);


and the java script side after using var d = JSON.parse(result1); and after echoing d i get :



enter code here
{\"columns\":[\"ROUTE\"],\"data\":[[{\"extensions\":{},\"labels\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/labels\",\"outgoing_relationships\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/relationships\/out\",\"traverse\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/traverse\/{returnType}\",\"all_typed_relationships\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/relationships\/all\/{-list|&|types}\",\"self\":\"http:\/\/localhost:7474\/db\/data\/node\/23\",\"property\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/properties\/{key}\",\"properties\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/properties\",\"outgoing_typed_relationships\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/relationships\/out\/{-list|&|types}\",\"incoming_relationships\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/relationships\/in\",\"create_relationship\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/relationships\",\"paged_traverse\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/paged\/traverse\/{returnType}{?pageSize,leaseTime}\",\"all_relationships\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/relationships\/all\",\"incoming_typed_relationships\":\"http:\/\/localhost:7474\/db\/data\/node\/23\/relationships\/in\/{-list|&|types}\",\"metadata\":{\"id\":23,\"labels\":[\"LandMark\"]},\"data\":{\"name\":\"Acharya College\"}}]]}"


But now i am stuck as to how to get to the property value as this does not quite seem like the key value JSON that i was trying to get my head around.



asked 1 min ago







Parsing a neo4j JSON object in javascript

Aucun commentaire:

Enregistrer un commentaire