如何使子字符串从单词错误到第一个逗号","?



我试图使这种类型的消息,我在PHP发送的子字符串,我做了一个小的代码,在本地工作,但当我想要该消息出现在我的数据库我得到一个奇怪的消息。

这个值想要子字符串,这是全文

Client error: `POST https://dev-platform.konfio.mx/core/transactions/424242/cancel` resulted in a `400 Bad Request` response:

{"error": {"message": {"ticket": ["必填项缺少数据。"], "approvedBy": ["必填项缺少数据。"(截断…)

我只想要这个子字符串:

{"error": {"message": {"ticket": ["Missing data for required field."]

这是我写的代码:

$this->setTicketStatus('error');
$message = $exception->getMessage();
$pal = 'response:';
$fin = ',';
$pos_inicio = strripos($message, $pal) + 11;
$pos_fin = stripos($message, $fin) - 1;
$msg = array();
$lon = strlen($message);
for ($i = 0; $i < $lon; ++$i) {
if ($i >= $pos_inicio and $i <= $pos_fin) {
$msg[] = $i;
}
}
$this->setMessageError(implode("|",$msg));

但是我收到了这个消息,我不知道为什么

Client error: `PUT https://dev-platform.konfio.mx/core/support/person/vasrvrvarvavrvrvw/birth` resulted in a `404 Not Found` response: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>404 Not Found</title> <h1>Not Found</h1> <p>The requested (truncated...)

由于响应似乎是一个JSON字符串,因此您可以解析JSON,然后获得所需的内容:

$data = json_decode(...);
$errorMessage = [];
$errorMessage['error']['message']['ticket'] = $data->error->message->ticket;

代码运行后,如果您愿意,可以将$errorMessage转换回JSON:

echo json_encode($errorMessage);

返回:

{"error": {"message": {"ticket": ["Missing data for required field."]}}}

相关内容

最新更新