Toshi
Toshi

Reputation: 302

JSON Escape Sequence

Im having trouble with my JSON because it show extra character which is not needed."\"enter image description here


this is the code i've use to query it from my dbase.

public function getPostList(){
    $query = "CALL sample3()";
    $result = mysql_query($query) or die(mysql_error());

    while ($row = mysql_fetch_array($result)) {
        $post = new Post();
        $post->setId($row['id']); 
        $post->setBody($row['body']); 
      //$post->setImage($row['imgurl']);
       $post->setImage("sgwebpost.atwebpages.com/". $row['imgurl']);
        $post->setStamp($row['stamp']);
        $postList[]  = $post;
    }

    return array('post'=> $postList);
}

echo json_encode($handler->getPostList());

How can i remove that extra string? Big Help Thanks.

Upvotes: 2

Views: 242

Answers (1)

Amal Murali
Amal Murali

Reputation: 76646

It's valid JSON, and is useful when there are </script> tags in your response, etc. But, if you want to remove it, you could use the JSON_UNESCAPED_SLASHES constant:

echo json_encode($handler->getPostList(), JSON_UNESCAPED_SLASHES);

Upvotes: 2

Related Questions