Page 1 of 1

Issue with JSON string

Posted: Wed Feb 03, 2016 9:05 am
by imaxeman69
I'm trying to use Dojo to make an Ajax call to a php program that returns a result set. I can see the json string in PHP Netbeans debugger just fine, but when it comes back to my script, the response is returning an Unexpected Token :. I think this means that it's seeing a colon (:) in the wrong place. The only thing I can think of is the PHP program is returning the JSON string wrapped in double quotes, which is throwing off the parser. When I copy the string from the Netbeans debugger and put it into JSONLint, it errors, but when I remove the outer quotes, it validates fine.

Funny thing is that if I call the php program that generates the JSON directly and just echo the results to the browser, I don't see the quotes.

Any Ideas on how to debug?

Thanks in advance.

Re: Issue with JSON string

Posted: Wed Feb 03, 2016 12:40 pm
by Christopher
The only thing I can think of is the PHP program is returning the JSON string wrapped in double quotes, which is throwing off the parser. When I copy the string from the Netbeans debugger and put it into JSONLint, it errors, but when I remove the outer quotes, it validates fine.

Funny thing is that if I call the php program that generates the JSON directly and just echo the results to the browser, I don't see the quotes.
You need to find out where the quotes are coming from. I suspect that you are adding them somewhere. And by quotes around the JSON, I am assuming that you mean something like ' "{ foo: "bar" }" '.