Issue with JSON string

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
imaxeman69
Forum Newbie
Posts: 4
Joined: Tue Jan 26, 2016 8:31 am

Issue with JSON string

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Issue with JSON string

Post 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" }" '.
(#10850)
Post Reply