ОШИБКА: com.android.volley.ParseError: org.json.JSONException: значение ‹!DOCTYPE типа java.lang.String не может быть преобразовано в JSONObject

JsonParse.Java Попытка получить объект массива json из URL-адреса, но он выдает ОШИБКУ синтаксического анализа
, а CountriedBean — это мой класс POJO.
parse_json имеет только ListView, а parse_json_view имеет 4 TextView.

Может ли кто-нибудь помочь мне ................

private List<CountriesBean> cntries= new ArrayList<CountriesBean>();
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.parse_json);

            RequestQueue queues = Volley.newRequestQueue(JsonParse.this);

            JsonObjectRequest myRequest = new JsonObjectRequest(Request.Method.GET,
                    "https://github.com/SaiNitesh/REST-Web-services/blob/master/RESTfulWS/json_file.json",
                    null,
                    new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {
                            try{
                                Log.i("myCountries**", "response:" +response);
                            JSONArray countryItems = response.getJSONArray("countryItems");

                            Log.i("myTagx", "response:" +countryItems);

                                for(int i=0; i<countryItems.length();i++){
                                    JSONObject temp= countryItems.getJSONObject(i);

                                    String nm = temp.getString("nm");
                                    String cty = temp.getString("cty");
                                    String hse = temp.getString("hse");
                                    String yrs = temp.getString("yrs");

                                    cntries.add(new CountriesBean(nm, cty, hse, yrs));
                                }
                            } catch(JSONException e){
                                Log.i("myTag",e.toString());
                            }
                        }
                    }, new Response.ErrorListener(){
                @Override
                public void onErrorResponse(VolleyError error){
                    Log.i("myTag", "Error:"+error.toString());
                }
            });

            queues.add(myRequest);

            ArrayAdapter<CountriesBean> adapter=new customAdapter();

            ListView myFirstListView = (ListView) (findViewById(R.id.myCountriesView));
            myFirstListView.setAdapter(adapter);


            myFirstListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
                //WebView myListViewbrowser = (WebView) findViewById(R.id.myListViewbrowser);
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    Toast.makeText(JsonParse.this,"My List View Item",Toast.LENGTH_SHORT).show();
                }
            });


        }

        private class customAdapter extends ArrayAdapter<CountriesBean>{
            public customAdapter() {
                super(JsonParse.this, R.layout.parse_json_view, cntries);

            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {

                /*getView method is like "for loop"
                For First time convertView=null, then it gets 1st list, then it returns(return convertView) the first list,
                then the convertView will be null
                After that it starts from here again for 2nd list and it continues*/
                if(convertView == null){
                    convertView = getLayoutInflater().inflate(R.layout.parse_json_view, parent,false);

                }


                TextView countryName = (TextView) convertView.findViewById(R.id.name);
                TextView countryCity = (TextView) convertView.findViewById(R.id.city);
                TextView countryHouse = (TextView) convertView.findViewById(R.id.house);

                CountriesBean myCurrentctries = cntries.get(position);


                countryName.setText(myCurrentctries.getNm());
                countryCity.setText(myCurrentctries.getCty());
                countryHouse.setText( myCurrentctries.getHse() );

                return convertView;
            }


        }

person Batman    schedule 01.12.2016    source источник
comment
Пожалуйста, опубликуйте также журнал ошибок   -  person Anuja Kothekar    schedule 01.12.2016


Ответы (1)


Ответ URL-адреса https://github.com/SaiNitesh/REST-Web-services/blob/master/RESTfulWS/json_file.json представляет собой HTML-страницу, поэтому вы получаете это исключение.

Пожалуйста, используйте https://raw.githubusercontent.com/SaiNitesh/REST-Web-services/master/RESTfulWS/json_file.json вместо этого.

person BNK    schedule 01.12.2016
comment
Как насчет того, если я хочу загрузить изображение в виде файла JSON? Как я могу показать это как необработанные данные? - person Batman; 26.12.2016
comment
Я думаю, вам следует создать новый вопрос для вашего нового требования, или вы можете выполнить поиск в SO, доступно много ссылок (одна из них stackoverflow.com/questions/16797468/) , но нужно еще уточнить, скачать или загрузить - person BNK; 26.12.2016