Невозможно поместить объект json в веб-просмотр? - PullRequest
0 голосов
/ 17 октября 2018

Это мой код,

final JsonObjectRequest obreq = new JsonObjectRequest(Request.Method.POST, JSON_URL,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    //hiding the progressbar after completion
                    /*progressBar.setVisibility(View.INVISIBLE);*/


                    try {
                        //getting the whole json object from the response
                        JSONObject obj = response.getJSONObject("data");
                        String color = obj.getString("data");
                        String desc = obj.getString("content");

                        data += "content: " + color +
                                "content_heading : " + desc;

                        /*mWebView.loadData(data, "text/html; charset=utf-8", "UTF-8");*/
                        mWebView.loadData(data, "text/html; charset=utf-8", "UTF-8");

                        //we have the array named hero inside the object
                        //so here we are getting that json array
                     /*   JSONArray cmsArray = obj.getJSONArray("data");*/

                        /*//now looping through all the elements of the json array
                        for (int i = 0; i < cmsArray.length(); i++) {
                            //getting the json object of the particular index inside the array
                            JSONObject cmsObject = cmsArray.getJSONObject(i);

                            //creating a hero object and giving them the values from json object
                            Cms cms = new Cms(cmsObject.getString("content"), cmsObject.getString("content_heading"), cmsObject.getInt("page_id"));



                        }*/



                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    //displaying the error in toast if occurrs
                    Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("page_id", "37");
            return params;
        }
    };

    VolleySingleton.getInstance(getActivity()).addToRequestQueue(obreq);
}

Я использую библиотеку залпа.здесь, в этой программе, я передаю page_id = 37 и получаю ответ, но я не могу установить ответ html, который находится в объекте для веб-просмотра в этой строке.

mWebView.loadData(data, "text/html; charset=utf-8", "UTF-8");

Это вызывает эту ошибку JSONObjectRequest ()в JSONObjectRequest не может быть применен.

Я получаю ответ в HTML-объект данных от json, я хочу отобразить это в веб-представлении, где это вызывает ошибку.Может ли кто-нибудь помочь мне в решении этой проблемы?

...