如何解析S3响应Guzzle \ Service \ Resource \ Model对象?

时间:2017-08-22 13:05:00

标签: php arrays object amazon-s3 s3-bucket

请求S3, v2 API。

$result = $client->getBucketLifecycleConfiguration(array(
    // Bucket is required
    'Bucket' => 'string',
));

我得到以下回复

Guzzle\Service\Resource\Model::__set_state(array(
   'structure' => NULL,
   'data' => 
  array (
    'Rules' => 
    array (
      0 => 
      array (
        'ID' => 'Test',
        'Filter' => 
        array (
          'Prefix' => 
          array (
          ),
        ),
        'Status' => 'Enabled',
        'NoncurrentVersionExpiration' => 
        array (
          'NoncurrentDays' => '250',
        ),
      ),
    ),
    'RequestId' => 'E83571AFC306FFFD',
  ),
))

我想解析这个对象!

尝试获取跟随$result->data的数据 NULL

我尝试将其强制转换为数组,但获得了以下数组索引。好像我做错了。

array (
  '' . "\0" . '*' . "\0" . 'structure' => NULL,
  '' . "\0" . '*' . "\0" . 'data' => 
  array (
    'Rules' => 
    array (
      0 => 
      array (
        'ID' => 'Test',
        'Filter' => 
        array (
          'Prefix' => 
          array (
          ),
        ),
        'Status' => 'Enabled',
        'NoncurrentVersionExpiration' => 
        array (
          'NoncurrentDays' => '250',
        ),
      ),
    ),
    'RequestId' => 'E83571AFC306FFFD',
  ),
)

1 个答案:

答案 0 :(得分:2)

查看http://docs.aws.amazon.com/aws-sdk-php/v2/guide/feature-models.html

根据链接,您可以使用$result->toArray()方法将模型转换为数组,或通过数组键直接访问所需的结果属性,即$result['Rules']