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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看