目前,我正在从PHP后端返回消息,如下所示:
$data = [ 'message' => 'Number doesn\'t exist!'];
$this->set_response(json_encode($data), REST_Controller::HTTP_CREATED);这将创建如下所示的消息:
"{\"message\":\"Number doesn't exist!\"}"然而,我希望得到这样的信息:
{
    "message": "Number doesn't exist!"
}我做错了什么?
发布于 2016-09-30 06:21:27
您可以使用JSON_UNESCAPED_SLASHES作为json_encode()中的第二个参数。
$data = [ 'message' => 'Number doesn\'t exist!'];
$encoded = json_encode($data,JSON_UNESCAPED_SLASHES);
$this->set_response($encoded, REST_Controller::HTTP_CREATED);其他解决方案:
$data = [ 'message' => 'Number doesn\'t exist!'];
$string = $this->set_response(json_encode($data), REST_Controller::HTTP_CREATED); // your current result
$decode = json_decode($string,true); // decode the value 
echo json_encode($decode,JSON_UNESCAPED_SLASHES); //and use JSON_UNESCAPED_SLASHES in json_encode()发布于 2016-09-30 06:16:28
兄弟,您只需将您的json称为json_encode($data,true),并像json_decode($data,true)那样对其进行解码;如果上面的代码似乎不起作用,那么请重新编写代码。
是转义作为响应一部分的引号(")。
使用strip斜杠()将其去掉。
当用引号包装的字符串包含引号时,必须转义它们。php中的转义字符是\
发布于 2016-09-30 06:18:15
您必须解码JSON响应。
json_decode($your_response);https://stackoverflow.com/questions/39784826
复制相似问题