Q:

Android hybrid app gives me "Uncaught SyntaxError: Unexpected identifier", source: (1)

I received a valid JSON from the server, but Chromium tells me this error:

"Uncaught SyntaxError: Unexpected identifier", source: (1)

All I know is that when I call the following method:
stringBuilder.append("javascript: javascriptBridge.getHandlers().showPost('");
stringBuilder.append(e.getData());
stringBuilder.append("');");
webView.loadUrl(stringBuilder.toString());

Where e.getData() is the valid JSON, it doesn't actually get called on the other side. Something in the JSON is interpreted incorrectly as a javascript function parameter
javascriptBridge.registerHandler('showPost', function (data) {
     alert('showpost'); //this is not called
});

It works for other datas and it worked previously even for JSON, that is why it's odd. Any ideas how to fix it? It's probably some character that crashes it.

A:

The following fixed it, thanks to commons-lang3:
 StringBuilder stringBuilder = new StringBuilder();
 stringBuilder.append("javascript: javascriptBridge.getHandlers().showPost('");
 stringBuilder.append(StringEscapeUtils.escapeEcmaScript(e.getData()));
 stringBuilder.append("');");
 webView.loadUrl(stringBuilder.toString());

