Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数组中获取内部消息_Php - Fatal编程技术网

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.