Is there a solution to prevent json_encode adding escape characters? I am returning a json obj from an ajax request.
Here is what I currently have:
foreach ($files as $file)
{
$inf = getimagesize( $file );
$farr[] = array (
"imgurl" => "/".str_replace( "\\" , "/" , str_replace( DOCROOT , "" , $file ) ) ,
"width" => $inf[0] ,
"height" => $inf[1]
);
}
$t = json_encode( $farr );
which delivers:
[
{\"imgurl\":\"\\\/_assets\\\/portfolio\\\/96\\\/full.png\",\"width\":580,\"height\":384},
{\"imgurl\":\"\\\/_assets\\\/portfolio\\\/95\\\/full.png\",\"width\":580,\"height\":452},
{\"imgurl\":\"\\\/_assets\\\/portfolio\\\/94\\\/full.png\",\"width\":580,\"height\":384}
]
but I need:
[
{imgurl:"/_assets/portfolio/96/full.png",width:580,height:384},
{imgurl:"/_assets/portfolio/95/full.png",width:580,height:452},
{imgurl:"/_assets/portfolio/94/full.png",width:580,height:384}
]
having the imgurl width and height indexes quoted is causing the rest of my javascript to break
not having much luck so any tips very much welcome...
json_encode()does the right thing. This means you must be doing something wrong. Please show the code that breaks.