3

I am using JSONKit in my iOS app. It loads an extremely simple JSON served by my php file:

http://staging.comwerks.net/terrence/ecitizen/article.php

somehow, it is producing an error: "Unexpected token, wanted '{', '}', '[', ']', ',', ':', 'true', 'false', 'null', '"STRING"', 'NUMBER'.}

When I try to use http://jsonlint.com/ to lint my URL above. It is giving a similar error complaining about the open bracket!

my php cant be more simple:

<?php
header('Content-type: application/json');
$json = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($json);
?>
1
  • +1 for an really well-presented question. Commented Apr 10, 2012 at 12:22

2 Answers 2

1

It might be complaining about the Unicode byte order mark at the start of the response. If I copy and paste the output into the linter, it validates. It's probably at the start of your article.php file. Your text editor should have an option to save without it (possibly in the Save As... dialog).

http://en.wikipedia.org/wiki/Byte_order_mark

Sign up to request clarification or add additional context in comments.

2 Comments

thanks nick... I resaved the php file using Notepad++ in UTF8-Without BOM. Then it works!
No problem. BOMs cause more problems than they solve so it's best to do without them wherever possible!
1

I agree with Nick. When I pulled the json directly to a file, my editor said the encoding was UTF-8 with BOM.

In addition the JSON validator you used gives me this error:

JSON Parse error: Unrecognized token '?'

Comments

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.