Weird character at start of json content type

Posted by Nek on Stack Overflow See other posts from Stack Overflow or by Nek
Published on 2010-03-19T05:12:24Z Indexed on 2010/03/19 5:21 UTC
Read the original article Hit count: 262

Filed under:
|
|

Hi, I'm trying to return json content read from MySQL server. This is supposed to be easy but, there is a 'weird' character that keeps appearing at start of the content.

I have two pages for returning content:

  1. kcb433.sytes.net/as/test.php?json=true&limit=6&input=d

    this test.php is from a script written by Timothy Groves, which converts an array to json output

  2. http://kcb433.sytes.net/k.php?k=4

    this one is supposed to do the same

I tried to validate it here jsonformatter.curiousconcept.com but just page 1 gets validated, page 2 says that it does not contain JSON data.

If accessed directly both pages has no problems. Then what is the difference, why both don't get validated?

Then I found this page jsonformat.com and tried the same thing. Page 1 was ok and page 2 wasn't but, surprisingly the data could be read. At a glance,

{"a":"b"}

may look good but there is a character in front.

According to a hex editor online, this is the value of the string above (instead of 9 values, there are 10):

-- 7B 22 61 22 3A 22 62  22 7D

The code to echo json in page 2 is:

header("Content-Type: application/json");
echo "{\"a\":\"b\"}";

© Stack Overflow or respective owner

Related posts about weird-behaviour

Related posts about character