2015-04-22 187 views
-1

該對象包含在$ response中。如何從PHP對象獲取參數?

echo "<pre>"; 
print_r($response); 
echo "</pre>"; 

..給我下面的:

Att\Api\Speech\SpeechResponse Object 
(
    [_responseId:Att\Api\Speech\SpeechResponse:private] => f4119dcd51929c2dfae5e2d746c1d9a1 
    [_status:Att\Api\Speech\SpeechResponse:private] => OK 
    [_NBest:Att\Api\Speech\SpeechResponse:private] => Att\Api\Speech\NBest Object 
     (
      [_hypothesis:Att\Api\Speech\NBest:private] => hi how are you 
      [_languageId:Att\Api\Speech\NBest:private] => en-US 
      [_confidence:Att\Api\Speech\NBest:private] => 0.5 
      [_grade:Att\Api\Speech\NBest:private] => accept 
      [_resultText:Att\Api\Speech\NBest:private] => Hi how are you. 
      [_words:Att\Api\Speech\NBest:private] => Array 
       (
        [0] => Hi 
        [1] => how 
        [2] => are 
        [3] => you. 
       ) 

      [_wordScores:Att\Api\Speech\NBest:private] => Array 
       (
        [0] => 0.33 
        [1] => 1 
        [2] => 1 
        [3] => 1 
       ) 

     ) 

    ) 

N00B的問題:如何將我現在能夠從_resultText獲得的價值?

+0

應該像$響應 - > getNBest() - > getResultText()? – Matheno

回答

1

在更廣泛的層面上的一個很好的問題,但可以通過該類本身的手冊輕鬆回答。

RTM

print_r($response->getNBest()->getResultText()); 
+0

你忘了getNBest,OP在語音對象 – Matheno

+0

謝謝!剛剛更新,而你正在打字:) –