【发布时间】:2012-04-18 16:10:56
【问题描述】:
我有一个带有 html 的 WebView,其中包含一个表单(帖子)。单击某个提交按钮时,我会收到 JSON 响应。
我怎样才能得到这个 JSON?
如果我不拦截请求,则 json 会显示在 webview 上,所以我想我应该使用shouldInterceptRequest(我正在使用 API 12),但我不知道如何获取其中的 json .
或者也许有更好的方法,比如拦截响应而不是请求?
mWebView.loadUrl(myURL);
isPageLoaded = false; // used because the url is the same for the response
mWebView.setWebViewClient(new WebViewClient() {
@Override
public WebResourceResponse shouldInterceptRequest (WebView view, String url) {
if(isPageLoaded){
// get the json
return null;
}
else return super.shouldInterceptRequest(view, url);
}
public void onPageFinished(WebView view, String url) {
isPageLoaded = true;
}
});
谢谢
【问题讨论】:
标签: android json post android-webview