A, JS method call Android
Andrews JS method call, and pass parameters json string format (JSONObject.toString ()),
例如: var json = {"name":"XJY","age":25",company":"CSII"};
Json directly as an argument: window.name.jsToClient (json);
Android Gets parameter is not available, print out is undefinded.
JS to this treatment, and then passed as a parameter to the original:
var jsonStr = JSON.stringify(json);
window.name.jsToClient(jsonStr);
So Android can receive json string.
Two, Android calls the JS method
Wrong, this is not received Android JS pass parameters
try{
JSONObject jsonObject = new JSONObject();
jsonObject.put ( "name", "San");
jsonObject.put(“age”,“100”);
jsonObject.put(“password”,“123456”);
String call = “javascript:clientToJS(\“”+jsonObject.toStirng+“\”)”;
mWebView.loadUrl(call);
}catch(Exception e){
}
Right, the easiest is to concatenate strings
---------------------
Author: xjy5566
Source: CSDN
Original: https: //blog.csdn.net/xjy5566/ article / details / 78607231
copyright: This article is a blogger original article, reproduced, please attach Bowen link!