从 android 调用 javascript 方法

Calling a javascript method from android

本文关键字:方法 javascript 调用 android      更新时间:2023-09-26

我有以下方法可以从安卓调用。我已经写了如下,但控制没有进入javascript。如果有人有任何解决方案,请告诉我。

String resp = javascript:httpservicesuccess("{'"code'":'"200'",'"requestID'":'"1000'",'"body'":'"{'"units'":{'"temperature'":'"C'",'"speed'":'"km'/h'",'"distance'":'"km'",'"pressure'":'"mb'"},'"location'":{'"location_id'":'"ITXX0024'",'"city'":'"Como'",'"state_abbreviation'":'"*'",'"country_abbreviation'":'"IT'",'"elevation'":935,'"latitude'":45.81000000000000,'"longitude'":9.08000000000000},'"wind'":{'"speed'":5.00000000000000,'"direction'":'"S'"},'"atmosphere'":{'"humidity'":'"47'",'"visibility'":9.99000000000000,'"pressure'":1016.00000000000000,'"rising'":'"steady'"},'"url'":'"http:'/'/weather.yahoo.com'/forecast'/ITXX0024.html'",'"logo'":'"http:'/'/l.yimg.com'/a'/i'/us'/nt'/ma'/ma_nws-we_1.gif'",'"astronomy'":{'"sunrise'":'"06:47'",'"sunset'":'"18:22'"},'"condition'":{'"text'":'"Fair'",'"code'":'"34'",'"image'":'"http:'/'/l.yimg.com'/a'/i'/us'/we'/52'/34.gif'",'"temperature'":10.00000000000000},'"forecast'":[{'"day'":'"Today'",'"condition'":'"Sunny'",'"high_temperature'":13.00000000000000,'"low_temperature'":3.00000000000000},{'"day'":'"Tomorrow'",'"condition'":'"Partly Cloudy'",'"high_temperature'":14.00000000000000,'"low_temperature'":5.00000000000000}]}'",'"headers'":{"Date":"Mon, 23 Apr 2012 03:50:41 GMT","Cache-Control":"public, max-age=1800","Expires":"Mon, 23 Apr 2012 04:20:41 GMT","Connection":"close","Transfer-Encoding":"chunked","Content-Type":"application/json;charset=UTF-8"}}")  
webView.loadUrl(resp);

谢谢
斯内哈

你错了。以这种方式使用它。它不是一个URL,而是一个HTML字符串。

webview.loadData(resp, "text/html", null);

编辑 - 使用正确的格式(我不确定文本/html是否正确)。但这就是您加载数据的方式。