Php 从响应中提取参数

Php 从响应中提取参数,php,curl,Php,Curl,我从CURL response中得到这个字符串 {status: 'false',description:'5400'} 我只想提取描述参数。 我想要$description=5400 如何做到这一点 该响应是json。将其转换为PHP数组: $response = "{status: 'false',description:'5400'}"; $response_array = json_decode($response, true); $description = $response_ar

我从CURL response中得到这个字符串

{status: 'false',description:'5400'}
我只想提取描述参数。 我想要$description=5400


如何做到这一点

该响应是json。将其转换为PHP数组:

$response = "{status: 'false',description:'5400'}";
$response_array = json_decode($response, true);
$description = $response_array['description'];
echo $description;

这个响应是json。将其转换为PHP数组:

$response = "{status: 'false',description:'5400'}";
$response_array = json_decode($response, true);
$description = $response_array['description'];
echo $description;

如果json响应不正确,则必须更改json代码,然后使用以下代码才能访问变量

<?php
$response = '{"status":false,"description":5400}';
$response_array = json_decode($response);
echo $response_array->description;
?>

如果您想使用现有的坏json获取描述值,可以执行以下操作

<?php
$response = "{status:'false',description:'5400'}";
$r = explode("description:'", $response);
$description = rtrim($r[1],"'}");
echo $description;
?>

如果json响应不正确,则必须更改json代码,然后使用以下代码才能访问变量

<?php
$response = '{"status":false,"description":5400}';
$response_array = json_decode($response);
echo $response_array->description;
?>

如果您想使用现有的坏json获取描述值,可以执行以下操作

<?php
$response = "{status:'false',description:'5400'}";
$r = explode("description:'", $response);
$description = rtrim($r[1],"'}");
echo $description;
?>
@

如果您的JSON带有空格,那么它将是写解决方案

$response=“{status:'false',description:'5400'}”

$response=str_replace(“,”,$response)

$response=preg_replace(“/\s+/”,“$response)

$t_repsonse=爆炸(“说明:”,$response)

$i_description=str_replace(“}”,“”,str_replace(“”,“”,$t_repsonse[1])

$i_description=str_replace(“}”,“”,preg_replace(“([“\”]),“$t_repsonse[1])

$description=$i_description

如果发现任何错误,请道歉并改进,谢谢

如果您的JSON带有空格,那么它将是写解决方案

$response=“{status:'false',description:'5400'}”

$response=str_replace(“,”,$response)

$response=preg_replace(“/\s+/”,“$response)

$t_repsonse=爆炸(“说明:”,$response)

$i_description=str_replace(“}”,“”,str_replace(“”,“”,$t_repsonse[1])

$i_description=str_replace(“}”,“”,preg_replace(“([“\”]),“$t_repsonse[1])

$description=$i_description


抱歉,如果发现任何错误,请改进,谢谢

您的json响应标题是否正确?我可以看到生成它的代码吗?json响应的头是否正确?我能看看你生成代码的地方吗?