如何在Android中加载Json数据到WebView?

3

我正在尝试解析HTML格式的JSON数据。我不明白如何实现。

我的JsonObject如下所示:

{"Content":
{
"PageContent":"<table cellpadding=\"1\" cellspacing=\"0\">\r\n\t<tr><td colspan=\"2\" style=\"font-weight:bold; font-style:italic; font-size:24px; color:Red; text-decoration:blink;\">Contact Us</td></table>"
}
}

我希望能够将HTML格式的i.e. menuPageContent JsonObject加载到WebView中。

2个回答

4

希望你知道如何在Android中实现JSON解析吗?(传送门)

不过,这里有一种从上述JSON中获取menuPageContent的方法:

String myJSONData = "place your data here";
JSONObject objJSON = new JSONObject(myJSONData);
JSONObject subObj = objJSON.getJSONObject("MenuContent");
String webData = subObj.getString("menuPageContent");

myWebView.loadData(webData, "text/html; charset=UTF-8", null);

阅读有关 WebView 的更多信息。


0

这个链接会对你有所帮助

http://code.google.com/p/google-gson/

WebView已经加载了数据,你可以使用它。

Gson gson = new Gson();
MyModel model = gson.fromJson("YOUR JSON DATA HERE", MyModel.class);
webView.loadData(model.menuPageContent, "text/html; charset=UTF-8", null);

抱歉,这不能帮助我解决问题。请检查问题。我想将其加载到WEBVIEW中。我能够获取Json。 - Rahul Baradia

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接