The JSON.parse() error means just what it says: there is an unexpected characer in your JSON data.<div><br></div><div>You didn't show us the JSON data itself, but the screenshot has enough of a clue about what went wrong.</div>


<div><br></div><div>Look at the call frame at the top of the stack: your nativeJSON() function. The variable named 'a' contains your JSON data, yes?</div><div><br></div><div>Look at that JSON string. It starts with several newlines (Windows-style newlines with \r\n), followed by:</div>


<div><br></div><div>    <--det...</div><div><br></div><div>That is the beginning of an HTML comment. It is not JSON.</div><div><br></div><div>Why is that in your JSON data? Look at your PHP file. It begins with a <?php section, but then it *ends* that section with ?> followed by this HTML comment:</div>


<div><br></div><div>    <!--determinar inicio e fim da rota--></div><div><br></div><div>There is your bad JSON data.</div><div><br></div><div>The fix is easy. Here is what you should do whenever you write a PHP file that generates JSON or any other non-HTML format:</div>


<div><br></div><div>1) Make sure the very first line of the file is <?php as you already have.</div><div><br></div><div>2) Do not end the PHP code with ?> anywhere. Don't even use ?> at the end of the file! Yes, that's right, don't use it at the end of the file. It is not required, and using it at the end of the file is likely to add an unnecessary newline because in most editors you'll probably have a newline after the ?>.</div>


<div><br></div><div>Those two rules insure that your entire PHP file is pure PHP code and does not have any spurious HTML code or HTML comments sneaking into your output data.</div><div><br></div><div>Of course, you will also now need to change your HTML comments to PHP // comments.</div>


<div><br></div><div>That should fix the JSON parsing error. At least it will insure that what the PHP code outputs is what you expect it to output.</div><div><br></div><div>-Mike<br><br><div class="gmail_quote">On Wed, Jul 11, 2012 at 4:53 AM, Pedro Costa <span dir="ltr"><<a href="mailto:pedrocostaarma@sapo.pt" target="_blank">pedrocostaarma@sapo.pt</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
This is my first mail to this list.<br>
<br>
I have a php script that have to return to client a geojson layer but it gives me this error in firebug:<br>
<br>
JSON.parse: unexpected character (screen shot attached)<br>
<br>
<br>
the php code is that:<br>
<br>
<a href="http://pastebin.com/tSCv5cnT" target="_blank">http://pastebin.com/tSCv5cnT</a><br>
<br>
<br>
Can somebody help me with the error?<br>
<br>
thanks<br>
<br>
<br>
<br>
<br>
<br>_______________________________________________<br>
Geojson mailing list<br>
<a href="mailto:Geojson@lists.geojson.org" target="_blank">Geojson@lists.geojson.org</a><br>
<a href="http://lists.geojson.org/listinfo.cgi/geojson-geojson.org" target="_blank">http://lists.geojson.org/listinfo.cgi/geojson-geojson.org</a><br>
<br></blockquote></div><br></div>