如何阅读google drive api提供的数组结果

时间:2016-07-13 07:00:00

标签: php json

我正在尝试通过google drive api阅读json,但无法读取json。

我正在尝试读取modelData:受保护的数据。

我在 $ result

下获得了以下结果
[0] => Google_Service_Drive_DriveFile Object (
    [modelData:protected] => Array
            (
                [labels] => Array
                    (
                        [starred] => 
                        [hidden] => 
                        [trashed] => 
                        [restricted] => 
                        [viewed] => 
                    )

                [parents] => Array
                    (
                        [0] => Array
                            (
                                [kind] => drive#parentReference
                                [id] => 0B4tddddcc03RW42UTdjUlY3SDg
                                [selfLink] => 
                                [parentLink] =>
                                [isRoot] => 
                            )

                    )

         )



)

我想读父母[0]

我写这段代码

foreach ($result as $res) {

print_r($res[modelData:protected]); 
}

这给了我错误

解析错误:语法错误,意外':',期待']'

有什么想法吗?如何解决这个问题

1 个答案:

答案 0 :(得分:0)

您已发布$result对象似乎是属于Google PHP库的Google_Service_Drive_DriveFile对象。

OOP visibility :: protected 的规则表示您无法访问课外的受保护的主题(通过Google搜索了解有关OOP可见性概念的更多信息)。

如果你想要与课程相关的所有功能的列表,你可以使用php get_class_methods()

print_R(get_class_methods($result));
# it will all methods available to this class.

或者您可以在库代码库中搜索符合您要求的所需方法。

根据Libray使用的编码标准,它为每个私有或受保护的属性使用getter和setter;

# for example if you want to access labels from above code then you can use 
$array = $result->getLabels();

# to get Parents
$parents = $result->getParents();

# if you want to set this properties you can use
$result->setLabels($array);