我努力寻找一种方法,将chyper查询的结果转换为Json字符串或对象,无论如何。
我尝试了几种方法。
$client = ClientBuilder::create()
->addConnection('default', 'http://XXX:XXX@XX.XXX.XX.XX:7474')
->build();
$query = "MATCH p=()-[:BETEILIGTER]->()-[:UNTERPROJEKT]->() RETURN p LIMIT 100";
$result = $client->run($query);
$result->records();
foreach ($result->records() as $record) {
print_r($record);
echo json_encode($record);
}
目前print_r($ record)显示数据。 但是,json_encode只返回空对象" {}"。 (1)我读到了变量可能受到保护的问题,我发现here但是这个变量对我没有用。 (2)我试图施放变量:
foreach ($result->records() as $record) {
$array = (array) $record;
echo json_encode($array);
}
但它并没有起作用。与第一个选项相比,结果有点多了:
{"\u0000*\u0000keys":["p"],"\u0000*\u0000values":[{}],"\u0000GraphAware\\Neo4j\\Client\\Formatter\\RecordView\u0000keyToIndexMap":{"p":0}}{"\u0000*\u0000keys":["p"],"\u0000*\u0000values":[{}],"\u0000GraphAware\\Neo4j\\Client\\Formatter\\RecordView\u0000keyToIndexMap":{"p":0}}
但仍然不是很多而不是我的预期。
(3)我在neo4j-php-client的源代码中找到了一个名为getJsonResponse()的函数。但是我无法调用该程序:
Call to undefined method GraphAware\Neo4j\Client\Formatter\Result::getJsonResponse() in /var/www/html/bpPhpHelper_4.php:15
甚至不知道这是否是一种有用的方法。
有没有人有什么好处?谢谢!
这里有一小段print_r($ record)结构:
{"\u0000*\u0000keys":["p"],"\u0000*\u0000values":[{}],"\u0000GraphAware\\Neo4j\\Client\\Formatter\\RecordView\u0000keyToIndexMap":{"p":0}}GraphAware\Neo4j\Client\Formatter\RecordView Object
(
[keys:protected] => Array
(
[0] => p
)
[values:protected] => Array
(
[0] => GraphAware\Neo4j\Client\Formatter\Type\Path Object
(
[nodes:protected] => Array
(
[0] => GraphAware\Neo4j\Client\Formatter\Type\Node Object
(
[id:protected] => 190256
[labels:protected] => Array
(
[0] => tibikatPerson
)
[properties:protected] => Array
(
[idTibikatPerson] => 13767
[sonstigeN] => 0
[person] => XXX, XXX
[verfasserN] => 0
[herausgeberN] => 0
[publicationN] => 1
[mitwirkenderN] => 0
)
)
[1] => GraphAware\Neo4j\Client\Formatter\Type\Node Object
(
[id:protected] => 101334
[labels:protected] => Array
(
[0] => fkatEinzelprojekt
)
[properties:protected] => Array
(
[zeOrt] => Dortmund
[zeBland] => Nordrhein-Westfalen
[ende] => 31.07.2015
[stName] => Gesellschaft für Bildung und Beruf e.V.
[stStadt] => Dortmund
[fSum] => 272104
[lpysyText] => Austausch mit anderen Staaten im Bereich der beruflichen Bildung sowie Stipendien
[lpsys] => YB1000
[tibikatUrl] => https://www.tib.eu/de/suchen/id/TIBKAT%3A869412949
[fkz] => 01BEX01D12
[zeName] => Gesellschaft für Bildung und Beruf e.V.
[thema] => Verbundprojekt: Aus- und Weiterbildung für die Fachrichtung Tierwirt/in - Schweinehaltung, Kennwort: Tierwirt/in (China), Teilvorhaben: 'Interkulturelle Projektsteuerung und Öffentlichkeitsarbeit'
[stOrt] => Dortmund
[zeStadt] => Dortmund
[beginn] => 01.08.2012
[stBland] => Nordrhein-Westfalen
)
)
[2] => GraphAware\Neo4j\Client\Formatter\Type\Node Object
(
[id:protected] => 174977
[labels:protected] => Array
(
[0] => fkatVerbundprojekt
)
[properties:protected] => Array
(
[einzelprojekteN] => 5
[ressort] => BMBF
[verbundprojektText] => Tierwirt China
[pt] => PT-DLR
[vkz] => 8732
[fSumTotal] => 792895
[ptEinheit] => BB
)
)
)
[relationships:protected] => Array
(
[0] => GraphAware\Neo4j\Client\Formatter\Type\Relationship Object
(
[id:protected] => 115390
[type:protected] => BETEILIGTER
[startNodeIdentity:protected] => 190256
[endNodeIdentity:protected] => 101334
[properties:protected] => Array
(
)
)
[1] => GraphAware\Neo4j\Client\Formatter\Type\Relationship Object
(
[id:protected] => 76338
[type:protected] => UNTERPROJEKT
[startNodeIdentity:protected] => 101334
[endNodeIdentity:protected] => 174977
[properties:protected] => Array
(
)
)
)
)
)
[keyToIndexMap:GraphAware\Neo4j\Client\Formatter\RecordView:private] => Array
(
[p] => 0
)
)
回答OldPadawan建议:
代码是:
<?php
require_once 'vendor/autoload.php';
use GraphAware\Neo4j\Client\ClientBuilder;
$client = ClientBuilder::create()
->addConnection('default', 'http://XXX:XXX@XX.XX.XX.XX:7474')
->build();
$query = "MATCH p=()-[:BETEILIGTER]->()-[:UNTERPROJEKT]->() RETURN p LIMIT 100";
$result = $client->run($query);
$list = array();
$element = array();
foreach ($result->records() as $record) {
// print_r($record);
$element = "$record";
array_push($list,$element);
// $array = (array) $record;
// echo json_encode($array);
}
//echo json_encode($list);
?>
错误:PHP Catchable致命错误:第23行的/var/www/html/bpPhpHelper_6.php中无法将GraphAware \ Neo4j \ Client \ Formatter \ RecordView类的对象转换为字符串
对OldPadawan建议的第二个答案:
你给了我这段代码
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
/* whatever params that are needed to be added here */
$client = ClientBuilder::create()
->addConnection('default', 'http://XXX:XXX@XX.XXX.XX.XX:7474')
->build();
$query = "MATCH p=()-[:BETEILIGTER]->()-[:UNTERPROJEKT]->() RETURN p LIMIT 100";
$result = $client->run($query);
$result->records();
foreach ($result->records() as $record) {
print_r($record);
}
echo json_encode($record);
?>
我将限制更改为&#34; 2&#34;由于回应的大小。
这是回复:
GraphAware\Neo4j\Client\Formatter\RecordView Object
(
[keys:protected] => Array
(
[0] => p
)
[values:protected] => Array
(
[0] => GraphAware\Neo4j\Client\Formatter\Type\Path Object
(
[nodes:protected] => Array
(
[0] => GraphAware\Neo4j\Client\Formatter\Type\Node Object
(
[id:protected] => 196717
[labels:protected] => Array
(
[0] => tibikatPerson
)
[properties:protected] => Array
(
[idTibikatPerson] => 20228
[sonstigeN] => 0
[person] => Wallussek, Ulrich
[verfasserN] => 0
[herausgeberN] => 0
[publicationN] => 2
[mitwirkenderN] => 0
)
)
[1] => GraphAware\Neo4j\Client\Formatter\Type\Node Object
(
[id:protected] => 100424
[labels:protected] => Array
(
[0] => fkatEinzelprojekt
)
[properties:protected] => Array
(
[zeOrt] => Halblech
[zeBland] => Bayern
[ende] => 30.11.2012
[stName] => ErduMo-S. GmbH & Co. KG - Nebenstelle
[stStadt] => Möhnesee
[fSum] => 147904
[lpysyText] => Austausch mit anderen Staaten im Bereich der beruflichen Bildung sowie Stipendien
[lpsys] => YB1000
[tibikatUrl] => https://www.tib.eu/de/suchen/id/TIBKAT%3A799010480
[fkz] => BEX017010
[zeName] => ErduMo-S. GmbH & Co. KG
[thema] => Verbundprojekt: Grubensicherheit in chinesischen Steinkohlebergbau, Teilvorhaben: Entwicklung und Vermarktung von Ausbildungs- und Weiterbildungsmodulen im Bereich des Arbeits- und Gesundheitsschutzes
[stOrt] => Möhnesee
[zeStadt] => Halblech
[beginn] => 01.10.2010
[stBland] => Nordrhein-Westfalen
)
)
[2] => GraphAware\Neo4j\Client\Formatter\Type\Node Object
(
[id:protected] => 170018
[labels:protected] => Array
(
[0] => fkatVerbundprojekt
)
[properties:protected] => Array
(
[einzelprojekteN] => 3
[ressort] => BMBF
[vkz] => 3773
[pt] => PT-DLR
[verbundprojektText] => Grubensicherheit im chinesischen Steinkohlebergbau - Entwicklung und Vermarktung von Ausbildungs- und Weiterbildungsmodulen im Bereich der Arbeits- und Grubensicherheit
[fSumTotal] => 200623
[ptEinheit] => BB
)
)
)
[relationships:protected] => Array
(
[0] => GraphAware\Neo4j\Client\Formatter\Type\Relationship Object
(
[id:protected] => 152288
[type:protected] => BETEILIGTER
[startNodeIdentity:protected] => 196717
[endNodeIdentity:protected] => 100424
[properties:protected] => Array
(
)
)
[1] => GraphAware\Neo4j\Client\Formatter\Type\Relationship Object
(
[id:protected] => 76187
[type:protected] => UNTERPROJEKT
[startNodeIdentity:protected] => 100424
[endNodeIdentity:protected] => 170018
[properties:protected] => Array
(
)
)
)
)
)
[keyToIndexMap:GraphAware\Neo4j\Client\Formatter\RecordView:private] => Array
(
[p] => 0
)
)
GraphAware\Neo4j\Client\Formatter\RecordView Object
(
[keys:protected] => Array
(
[0] => p
)
[values:protected] => Array
(
[0] => GraphAware\Neo4j\Client\Formatter\Type\Path Object
(
[nodes:protected] => Array
(
[0] => GraphAware\Neo4j\Client\Formatter\Type\Node Object
(
[id:protected] => 178170
[labels:protected] => Array
(
[0] => tibikatPerson
)
[properties:protected] => Array
(
[idTibikatPerson] => 1681
[sonstigeN] => 0
[person] => Blümke, D.
[verfasserN] => 0
[herausgeberN] => 0
[publicationN] => 2
[mitwirkenderN] => 0
)
)
[1] => GraphAware\Neo4j\Client\Formatter\Type\Node Object
(
[id:protected] => 100424
[labels:protected] => Array
(
[0] => fkatEinzelprojekt
)
[properties:protected] => Array
(
[zeOrt] => Halblech
[zeBland] => Bayern
[ende] => 30.11.2012
[stName] => ErduMo-S. GmbH & Co. KG - Nebenstelle
[stStadt] => Möhnesee
[fSum] => 147904
[lpysyText] => Austausch mit anderen Staaten im Bereich der beruflichen Bildung sowie Stipendien
[lpsys] => YB1000
[tibikatUrl] => https://www.tib.eu/de/suchen/id/TIBKAT%3A799010480
[fkz] => BEX017010
[zeName] => ErduMo-S. GmbH & Co. KG
[thema] => Verbundprojekt: Grubensicherheit in chinesischen Steinkohlebergbau, Teilvorhaben: Entwicklung und Vermarktung von Ausbildungs- und Weiterbildungsmodulen im Bereich des Arbeits- und Gesundheitsschutzes
[stOrt] => Möhnesee
[zeStadt] => Halblech
[beginn] => 01.10.2010
[stBland] => Nordrhein-Westfalen
)
)
[2] => GraphAware\Neo4j\Client\Formatter\Type\Node Object
(
[id:protected] => 170018
[labels:protected] => Array
(
[0] => fkatVerbundprojekt
)
[properties:protected] => Array
(
[einzelprojekteN] => 3
[ressort] => BMBF
[vkz] => 3773
[pt] => PT-DLR
[verbundprojektText] => Grubensicherheit im chinesischen Steinkohlebergbau - Entwicklung und Vermarktung von Ausbildungs- und Weiterbildungsmodulen im Bereich der Arbeits- und Grubensicherheit
[fSumTotal] => 200623
[ptEinheit] => BB
)
)
)
[relationships:protected] => Array
(
[0] => GraphAware\Neo4j\Client\Formatter\Type\Relationship Object
(
[id:protected] => 152287
[type:protected] => BETEILIGTER
[startNodeIdentity:protected] => 178170
[endNodeIdentity:protected] => 100424
[properties:protected] => Array
(
)
)
[1] => GraphAware\Neo4j\Client\Formatter\Type\Relationship Object
(
[id:protected] => 76187
[type:protected] => UNTERPROJEKT
[startNodeIdentity:protected] => 100424
[endNodeIdentity:protected] => 170018
[properties:protected] => Array
(
)
)
)
)
)
[keyToIndexMap:GraphAware\Neo4j\Client\Formatter\RecordView:private] => Array
(
[p] => 0
)
)
{}
最后一篇&#34; {}&#34;是&#34; echo json_encode($ record);&#34;其余的由&#34; print_r($ record);&#34;没有报告错误。