JSONParser.parseStrict() exception "Unexpected token <"

496 views
Skip to first unread message

seven.reeds

unread,
Jul 31, 2012, 5:58:02 PM7/31/12
to google-we...@googlegroups.com
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

Colin Alworth

unread,
Jul 31, 2012, 9:12:43 PM7/31/12
to google-we...@googlegroups.com
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.

seven.reeds

unread,
Aug 1, 2012, 1:27:38 PM8/1/12
to google-we...@googlegroups.com
Hi Colin,

Thanks! Your ideas moved me towards a solution.  Turns out that FormPanel->onSubmitComplete returns whatever is returned as "html".  My result was surrounded by PRE tags.  I sucked the getResult output into a HTML instance and then used the getText method to get what I wanted.

This is also the first time I have used the GWT Logging tools.  very nice.

Thanks again
seven
Reply all
Reply to author
Forward
0 new messages