Pregunta

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);
?>
¿Fue útil?

Solución

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

Otros consejos

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 '?'

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top