Php 从数组中获取内部消息
因此,我通过条带检索一条失败消息,其中包含失败的信用卡费用,如下所示:Php 从数组中获取内部消息,php,Php,因此,我通过条带检索一条失败消息,其中包含失败的信用卡费用,如下所示: echo $response['failure_message']; 这反映了: string(185) "{ "error": { "message": "The 'exp_month' parameter should be an integer (instead, is MM).", "type": "card_error", "param": "exp_month", "code
echo $response['failure_message'];
这反映了:
string(185) "{
"error": {
"message": "The 'exp_month' parameter should be an integer (instead, is MM).",
"type": "card_error",
"param": "exp_month",
"code": "invalid_number"
}
}
如何仅从该字符串获取消息
我试过:
echo $response['failure_message']['message'];
但它也反映了同样的情况。我只想呼应一下这个信息 使用将有效负载从json转换为php数组
$message = json_decode($response['failure_message']);
echo $message['error']['message']
这将返回“exp_month”参数应该是整数(而是MM)。这是因为它返回的是JSON字符串,而不是多维数组。您需要解码JSON字符串 试着这样使用:
$result = json_decode($response['failure_message'])
echo $result['error']['message']; //Should return just the message string.
您需要使用以下命令:echo$response['failure_message']['error']['message'];您真的是从
echo
而不是var\u dump
获得输出吗?
$result = json_decode($response['failure_message'])
echo $result['error']['message']; //Should return just the message string.