繁体   English   中英

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

[英]How can I load Json data to WebView in Android?

我正在尝试解析 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>"
}
}

我想将 jsonobject ie menuPageContent加载到 WebView 的 HTML 格式。

希望你知道如何在 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 的更多信息。

此链接将对您有所帮助

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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM