【问题标题】:How get response from podio api in format json or array but not object?如何以json或数组格式从podio api获得响应,但不是对象?
【发布时间】:2017-10-19 19:03:59
【问题描述】:

如何从 podio api 以 json 或数组格式而不是对象获取响应? 我使用 podio-php (https://github.com/podio/podio-php)

我的代码

    Podio::setup(CLIENT_ID_PODIO, CLIENT_SECRET_PODIO);
    $oauth = Podio::is_authenticated(); 
    Podio::authenticate_with_app(111111, 
              'bergbttyjra74d5afgrfhgrh781e70');
    //$items = PodioItem::filter(111111);
    $item = PodioItem::filter(111111, array(
        'filters' => array(
            'created_on' => array(
                "from" => "2017-10-09 00:00:00",
                "to" => "2017-10-19 23:59:59"
            )
        ),
    ));
   // print_r($item);// output object
 // how next ?

【问题讨论】:

  • 对象有什么问题?
  • 我不知道如何从对象中获取数据作为这个 PodioByLine 对象 ( [__attributes:PodioObject:private] => Array ( [type] => user [id] => 4286469 [avatar_type] = > 文件 [avatar_id] => 422384899 [图像] => 数组 ( [hosted_by] => 播音台 [hosted_by_humanized_name] => 播音台 [thumbnail_link] => d2cmuesa4snpwn.cloudfront.net/public/422384899 [链接] => d2cmuesa4snpwn.cloudfront.net/public/422384899 [file_id] => 422384899 [ external_file_id] => [link_target] => _blank) [name] => FGfwegf fegfe
  • 那么阅读文档? podio.github.io/podio-php/objects
  • 是的,我读过文档
  • 文档解释了如何使用对象及其数据,包括代码示例。

标签: php json podio


【解决方案1】:

假设您确实需要 JSON 或数组,除了 “我不知道如何处理一个对象”。所以对于 JSON,只需使用 as_json() 函数。并获得一个数组只是typecast an object

所以:

 $json = $item->as_json(); // converts to json
 $array = (array) $item;   // converts to array

但@ceejayoz 在上面的 cmets 中是正确的:对象本身很好,只是 RTFM :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-23
    • 2011-02-18
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-29
    • 1970-01-01
    相关资源
    最近更新 更多