Ryan Temple Ryan Temple - 2 months ago 18
Java Question

onJsAlert return message is object not string

I'm making a call

webView.loadUrl("javascript:alert(javascriptFunc()));
webView.setUpWebChromeClient( new WebChromeClient() {


@Override
public boolan onJsAlert(WebView view, String url, final String message, JsResult result) {
....
}});


The message im getting is coming back as

[object Object];


It's supposed to be a JSON object thats the response however I can only get the String representation of the object. Please help on how I would access the object!

Answer

It's probably a json object but you are viewing it as a String. So you will need to translate the object to a String representation using JSON.stringify if you want to view it:

javascript:alert(JSON.stringify(javascriptFunc()));

Instead of

javascript:alert(javascriptFunc());
Comments