我有一个数组,我正在尝试解码和解析 json 值,但无法正确处理。
这是信息:
$send[0] :
Array ( [0] => {"message-count":"1","messages":[{"error-text":"Missing to param","status":"2"}]} )
var_dump(json_decode($v_send[0]));
/* output
json Dunmpobject(stdClass)#1 (2) { ["message-count"]=> string(1) "1" ["messages"]=> array(1) { [0]=> object(stdClass)#2 (2) { ["error-text"]=> string(16) "Missing to param" ["status"]=> string(1) "2" } } }
*/
var_dump(json_decode($v_send[0], true));
/* output
array(2) { ["message-count"]=> string(1) "1" ["messages"]=> array(1) { [0]=> array(2) { ["error-text"]=> string(16) "Missing to param" ["status"]=> string(1) "2" } } }
*/
$json=json_decode($v_send[0]);
echo "Start:";
echo "<br/><br/>";
// To loop
if (!is_array($json)) die('...');
foreach ($json as $key=>$tts_result)
{
echo $tts_result->callid;
echo "<br/><br/>";
echo $tts_result->to;
echo "<br/><br/>";
echo $tts_result->messages["status"];
echo "<br/><br/>";
echo $tts_result->error-text;
}
循环中的回声给出空结果。任何人都可以帮忙吗?