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.