2

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.

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Accepted :) I will ask another question again i hope you can help me again.
@Toshi: Glad to have been of help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.