Tuesday, July 31, 2012

Re: JSONParser.parseStrict() exception "Unexpected token <"

Your catch (Exception e) should also be printing out the results, but your quoted error message didn't contain that exact json - any chance that the json you started with isn't actually making it to the client? One simple way to test would be to escape that string and put it in your Java code (instead of event.getResults()) and make sure it can parse that way. If this fails, something is up in how JSONParser.parseStrict is working, though this leans on the browser itself, suggesting there is something up with the browser. It seems more likely to me though that the service that is returning your json is wrapping it in HTML, making it no longer valid json.

Your method of printing out error text might be hiding this - you are rendering the message _as_ HTML, which will make any html tags appear as rendered content. Try a real logger, or escape the content before you put it in the HTML widget.

On Tuesday, July 31, 2012 4:58:02 PM UTC-5, seven.reeds wrote:
Hi,

GWT 2.4.0
Eclipse Juno
Ubuntu

I am using a GWT Form.  In the form.addSubmitCompleteHandler() I do the following:

try {
Info = JSONParser.parseStrict(event.getResults()).isObject();
} catch (NullPointerException e) {
RootPanel.get("list").clear();
RootPanel.get("list").add(new HTML("<p><NullPointerException: "
+ e.getMessage() + "<br/><kbd>" 
+ event.getResults() + "</kbd></p>"));
return;
} catch (IllegalArgumentException e) {
RootPanel.get("list").clear();
RootPanel.get("list").add(new HTML("<p>IllegalArgumentException: "
+ e.getMessage() + "<br/><kbd>" 
+ event.getResults() + "</kbd></p>"));
return;
} catch (Exception e) {
RootPanel.get("list").clear();
RootPanel.get("list").add(new HTML("<p>Exception: " + e.getMessage()
+ "<br/>Cause: " + e.getCause()
+ "<br/><kbd>" 
+ event.getResults() + "</kbd></p>"));
return;
}

It is trying to parse:

{"table":{"MOLINE.EWR.UIND.EDU":{"SONGS":[["07/04/2012 12:23:37","07/04/2012 12:51:16",0.4608,""]]}}}

The "catch (Exception e)" case reports:  "Exception: Error parsing JSON: SyntaxError: Unexpected token <
Cause: null"

There are no "<"s, or tabs in there.  What gives?  This is actually part of a MUCH larger parse string but it fails no matter how many records it sees.

I am doing the same or similar things with older GWT projects without issues.


thanks,
seven

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/bmRnZKDoUToJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment