我正在尝试在以下代码中访问文本“ Passion”,但我不知道如何操作。现在我只能得到
{"parts": [{"text": "Passion"]}
谁能告诉我下一步该怎么做?谢谢!
$test =
'{
"event":
{
"response":"{\"parts\": [{\"text\": \"Passion\"]}"
},
"event_source":"server"
}';
$jarray = json_decode($test, true);
echo $jarray['event']['response'];
答案 0 :(得分:2)
您的json数据在这里无效:-
"{\"parts\": [{\"text\": \"Passion\"]}"
//----------------------------------^ one } needed before ]
更正输入后,请执行以下操作:
<?php
$test =
'{
"event":
{
"response":"{\"parts\": [{\"text\": \"Passion\"}]}"
},
"event_source":"server"
}';
$jarray = json_decode($test, true);
print_r($jarray);
$response = json_decode($jarray['event']['response'], true);
echo $response['parts'][0]['text'];