2017-08-28 64 views
-1

我有这样的结果,但它does'tn显示这样的结果:$toto->speech如何显示一个JSON元素

$toto = json_encode($response); 
    var_dump($toto); 
string(665) "{"id":"011d8627-d6f9-42e1-9f28-f64f273f5211","timestamp":"2017-08-28T01:15:42.16Z","lang":"en","result":{"source":"agent","resolvedQuery":"Hello","action":"input.welcome","actionIncomplete":false,"parameters":[],"contexts":[],"metadata":{"intentId":"5293f9c1-0755-4df0-b97c-6406ddeef2c2","webhookUsed":"false","webhookForSlotFillingUsed":"false","intentName":"Default Welcome Intent"},"fulfillment":{"speech":"Hello! Welcome on Alicia Bot. I will tried to help you.","messages":[{"type":0,"speech":"Hello! Welcome on Alicia Bot. I will tried to help you."}]},"score":1},"status":{"code":200,"errorType":"success"},"sessionId":"8eadeb6f-8b32-43cb-8ed8-8e217d053a12"}" 

现在我尝试这样做:

echo '<br>--------<br>'; 
echo $toto->speech; 

回答

0

试试这个

echo $toto->result->fulfillment->speech; 

echo $toto["result"]["fulfillment"]["speech"];