0

我对PHP53所以codeception 1.8访问阵列值

$response = (array)$I->grabDataFromJsonResponse("result"); 
\Codeception\Util\Debug::debug($response); 

    Array 
    (
     [*position] => 0 
     [*val] => Array 
      (
       [key1] => 10 
       [key2] => 1 
     ) 

     [*assocArray] => 1 
) 

现在,当我试图访问它给数组中的值Me错误

\Codeception\Util\Debug::debug($response['key1']); 

[ErrorException] Undefined index: key1 
+0

理所应当的。试试'\ Codeception \ Util \ Debug :: debug($ response ['* val'] ['key1']);' – Calimero

+0

@Calimero我试过了,说“Undefined index:* val”如何获取值? – SoulMan

+0

$ response [0] ['* val'] ['key1'] –

回答

1

这是因为Object -> array conversion

要访问受保护的属性(前缀为*),必须包含基于空的字节:

$response["\0*\0val"]['key1']

(注意双引号)

+0

This Works!不过,我也在寻找一个答案,我可以使用codeception BDD样式API直接从响应中获取数组。 – SoulMan

+0

是不是grabDataFromJsonResponse这样做? – Naktibalda

+0

@Naktibalda grabDataFromJsonResponse无法在涉及数组时使用路径。有什么建议么 ? – SoulMan