The code I have used:
$val = json_encode(array("test"=>test1,"test2" =>test,"description" => description));
return $val;
The result im getting
{\"test\":\"test1\",\"test2\":\"test\",\"description\":\"description\"}
I need this to fix api
The code I have used:
$val = json_encode(array("test"=>test1,"test2" =>test,"description" => description));
return $val;
The result im getting
{\"test\":\"test1\",\"test2\":\"test\",\"description\":\"description\"}
I need this to fix api
Try with stripslashes()
echo stripslashes('{\"test\":{\"test1\":{\"test1\":[{\"test2\":\"1\",\"test3\": \"foo\",\"test4\":\"bar\",\"test5\":\"test7\"}]}}}');
Tried this.
$val = json_encode(array(
"test"=>'test1',
"test2" =>'test',
"description" => 'description'
));
$data = json_decode($val, true, JSON_UNESCAPED_SLASHES);
return $data;
This is the result I received.
In php "stripslashes" function is present using that you can remove backslash.
Example:
echo $strnew = stripslashes('{\"test\":{\"test1\":{\"test1\":[{\"test2\":\"1\",\"test3\": \"foo\",\"test4\":\"bar\",\"test5\":\"test7\"}]}}}');
Use stripslashes()
And read stripslashes
<?php
$srt="'{\"test\":{\"test1\":{\"test1\":[{\"test2\":\"1\",\"test3\": \"foo\",\"test4\":\"bar\",\"test5\":\"test7\"}]}}}'
";
echo stripslashes($srt);
OUTPUT
'{"test":{"test1":{"test1":[{"test2":"1","test3": "foo","test4":"bar","test5":"test7"}]}}}'
you can use JSON_UNESCAPED_SLASHES
json_encode($yourjson, JSON_UNESCAPED_SLASHES);
Use string find and replace function
$str="{"test":{"test1":{"test1":[{"test2":"1","test3": "foo","test4":"bar","test5":"test7"}]}}}";
str_replace("\'","'",$str);
Try the following code. It works perfectly fine for me $cha
a string with backslashes
$cha = "{\"ashen\":\"143\"}";
$chachi = json_decode($cha,JSON_UNESCAPED_SLASHES);
return $chachi['ashen'];
output: 143
Actually, only Khachornchit Songsaen answer is correct.
stripslashes
does not work on unescaping escaped " in json encoded strings inside another json.
es.
{ "key1" :"value1", "key2": "{\"key\":\"Text \\\"text\\\" text\"}" }
using json_decode($var, true, JSON_UNESCAPED_SLASHES)
does the job correctly.
this is the right method when your result is coming in slashes do this
$data = [
"message" => '',
"data" => $product
];
$response[] = $data;
return $response;
do this it's really work because after 5 day i fund this solution or it is right .
I was facing same issue, it is resolved by using echo and exit;
$response = json_encode(array("test"=>"test1","test2" =>"test","description" => "description"));
echo $response; exit;