JSON generated by json_encode gives error in character "{"

Asked

Viewed 326 times

2

I don’t understand what’s going on, I’m using a function json_encode in PHP and what it returns is invalid?!

I am using the jsonlint as validator, and he claims that the error is in the first {. If I replace this character with another {, it says it’s valid. Am I using any incorrect encoding in the file? To my eyes the character looks exactly the same. Below is the returned function:

{
   "status": 1,
   "page": "1",
   "content": "foo",
   "hasNext": true
}

Apparently there is something wrong between this character -> { <-(copied) and this -> { <- (typed), but it seems to be the same... I’m going crazy, someone has some assumption of what might be?

1 answer

5


Everything indicates that your PHP is sending something else before the {. Check that your file is saved as UTF-8 with BOM (byte-order Mask), as BOM would invalidate JSON.

To check, open in an editor like Notepad++ and save the file as UTF-8 without BOM.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.