douyingmou1389 2016-07-13 06:59
浏览 42
已采纳

如何阅读谷歌驱动api提供的数组结果[复制]

This question already has an answer here:

I am trying to read json provide by google drive api, but not able to read json.

i am trying to read modelData:protected data.

I got following result under $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] => 
                            )

                    )

         )



)

and i am trying to read parents[0]

And i write this code

foreach ($result as $res) {

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

This gives me error

Parse error: syntax error, unexpected ':', expecting ']' in

Any idea? how to resolve this issue

</div>
  • 写回答

1条回答 默认 最新

  • dongse7261 2016-07-13 09:10
    关注

    You are posted $result object seems to be a Google_Service_Drive_DriveFile Object which is belong to google PHP library.

    The rule of OOP visibility::protected says that you cannot access that protected propery outside of class(learn more about OOP Visibility concept through googling it).

    if you want list of all functions releted to class you can use php get_class_methods()

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

    or you can search through a library codebase for desired method which fit's your requirement.

    As per the coding standards used by the Libray it's uses getters and setters for every private or protected property;

    # 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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档