Parsing a neo4j JSON object in javascript

老子叫甜甜 提交于 2019-12-11 07:04:12

问题


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:

<?php
header('Access-Control-Allow-Origin: *');
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 :

{\"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.

来源:https://stackoverflow.com/questions/28270091/parsing-a-neo4j-json-object-in-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!