【发布时间】:2016-03-30 18:21:38
【问题描述】:
我有以下查询 couchbase 数据库的 php 逻辑:
$myCluster = new CouchbaseCluster('couchbase://localhost');
$bucket = $myCluster->openBucket('reporting');
$result = $bucket->get('server_details_1');
$doc = $result->value;
var_dump($doc);
echo $doc->server_details->name."\n";
最后一行失败了,因为我认为我尝试访问 json 对象的方式不正确。也许它不再是一个 json 对象......我不太确定。但我确实知道 couchbase 将它作为 json 存储在数据库本身中。
这是 var_dump 命令返回的内容,它显示了对象的结构:
string '{"server_details":{"name":"test_server","dns_name":"test.server.mydomain.net","ipv4":"10.1.16.106","ipv6":"","type":"primary"},"server_status":{"up_to_date":true},"packages":{"pack1":{"current_version":"x.x","previous_version":"x.x","last_updated_on":"2016-03-16","play_id":"link to audit table"},"pack2":{"current_version":"x.x","previous_version":"x.x","last_updated_on":"2016-03-16","play_id":"link to audit table"}}}' (length=438)
【问题讨论】:
-
这是一个有效的 json 字符串,但您必须让 php 将其作为对象读取才能执行您想要执行的操作(json_decode)