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.
Issue with JSON string
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Issue with JSON string
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" }" '.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.
(#10850)