Reputation: 302
Im having trouble with my JSON because it show extra character which is not needed."\"
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
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