需要从json值

时间:2017-09-08 07:21:51

标签: php json web-services codeigniter codeigniter-3

我需要从codeigniter中删除\, 这是我的输出:

{
    "id": "3496",
    "label": "B\\'less S\\'On Chicken Leg 200-240g",
    "sku": "",
    "cat_id": "72",
    "slug": "b-less-s-on-chicken-leg-200-240g",
    "product_min_order_qty": "1",
    "product_unit_type": "pkt",
    "alter_unit_type": "",
    "product_short_desc": null,
    "product_long_desc": "B\\'less S\\'On Chicken Leg 200-240g\r\n\r\n8 X 2kg / ctn",
    "image": null
}

以下是我的代码:

$product_res = $this->Mydb->get_all_records('*', 'table_name');
$responseData = array("status" => 'ok',"categories" => $category_res,"products" => $product_res,"search_count" => $search_count, "Response" => array("response" => "Success", "response_code" => 1));    
$this->output->set_content_type('application/json;'); 
$this->output->set_header('Access-Control-Allow-Origin: *');
return $this->output->set_output(json_encode($responseData,JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));

3 个答案:

答案 0 :(得分:2)

只需使用stripslashes功能

即可
return $this->output->set_output(stripslashes(json_encode($responseData,JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)));

答案 1 :(得分:1)

试试这个

var finalData = str.replace(/\\/g, "");

答案 2 :(得分:1)

尝试修剪功能

$ responseData = array(“status”=>'ok',“categories”=> trim($ category_res),“products”=> trim($ product_res),“search_count”=> $ search_count ,“响应”=>数组(“响应”=>“成功”,“response_code”=> 1));