JSON "eval" error?


Web tier: servlets, JSP, Web frameworks: JSON "eval" error?

  1. JSON "eval" error? (1 messages)

    Hi, I'm using JSON via JSRS (a kind of simpler pre-cursor to AJAX) with a J2EE application. We have a complex XSLT-based user interface and I'm using AJAX to refresh the screen without users seeing a visible refresh "flash" (and loosing their place in the screen). However I have an odd fault that I've been unable to debug. Basically when I invoke one of our generic JSRS calls on most of our screens, it works fine (and refreshes part of the screen). However on one of our screens it fails with the following error: SyntaxError: Expected '}' The JSON is of the following form: {"html":"...","message":null,"error":false} (where html is about 120K of escaped HTML, like the following \r\n My JavaScript code is as follows (I've had to rename the standard JavaScript eval method to allow this post): function updateScreenCallback(result) { try { var result = _eeval_('(' + result + ')'); if (result.error) { alert(result.message); } else { document.forms[1].outerHTML = result.html; } } catch (e) { if (e instanceof Error) { alert(e.name + ': ' + e.message); } } } I'm using the Java classes from json.org unaltered, but can't see any obvious escaping errors or line returns etc. If I copy and paste the JSON text into a standalone HTML page I don't get any errors. Also if I use a simulated result with 120K of data it also works fine. I can provide the "real" data if it helps. Via some extra JavaScript debug code I've managed to determine that there are no new lines, form feeds or carriage return characters in the JSON text, nor any un-escaped double quotes. Does anyone know if any further characters need to be escaped, such as : [] { } ' ? Can anyone please suggest where I'm going wrong, or if anyone else has experienced something similar? Thanks, Chris.
  2. Hi Chris, I was baffled by this annoying and non-descript JavaScript error after calling down JSON data for a tutorial I did: http://www.jasonsalas.com/2006/05/convert-xml-to-json-through-xslt-for.html I figured it out today that the error is evidently caused by unescaped characters. In my app, it was quotations - "" - not being properly escaped and then wrecking the eval'ing in JS. Hope this helps!