开发者

iPhone 4 Pass JSON string to Javascript within a Web View

开发者 https://www.devze.com 2023-04-11 19:40 出处:网络
I know this is possible in Java with Javascript handler : graphView.addJavascriptInterface(handler, \"javahandler\");

I know this is possible in Java with Javascript handler :

   graphView.addJavascriptInterface(handler, "javahandler");
   graphView.loadUrl("file:///android_asset/html/show_data_from_file.html");

    JSONObject json = new JSONObject();
    json.put("data", jsonArray);
    json.put("label","labelString");
    handler.json = json;

Within the javascript page, the "javahandler" would have "json" object, which开发者_如何学Go I can get the data array and the label to display on the page.

Is there something similar for iOS? I'm very new to web programming with iOs, and would appreciate your help!


You can use stringByEvaluatingJavascriptFromString to call a javascript method and pass your JSON string through that method,

[yourWebViewInstance stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"useThisJSONString(%@)", JSONString]];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号