【问题标题】:How can I load Json data to WebView in Android?如何在 Android 中将 Json 数据加载到 WebView?
【发布时间】:2013-01-17 07:04:40
【问题描述】:

我正在尝试解析 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 格式的 jsonobject i.e. menuPageContent 加载到 WebView。

【问题讨论】:

    标签: android json android-webview


    【解决方案1】:

    希望你知道how to implement JSON Parsing in Android

    不过,这里有一种从上面的 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的信息。

    【讨论】:

    • 非常感谢.. 我明白了。 . . . :)
    【解决方案2】:

    此链接将对您有所帮助

    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。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    • 2016-12-26
    • 2013-04-11
    • 2012-03-11
    • 2015-02-01
    相关资源
    最近更新 更多