Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何实现GSON@SerializedName我在DoInBackground中收到错误_Android_Performance_Shell_Android Layout_Android Fragments - Fatal编程技术网

Android 如何实现GSON@SerializedName我在DoInBackground中收到错误

Android 如何实现GSON@SerializedName我在DoInBackground中收到错误,android,performance,shell,android-layout,android-fragments,Android,Performance,Shell,Android Layout,Android Fragments,如何实现GSON@SerializedName我在ModelClass ModelClass=new GSON().fromJson(响应,ModelClass.class)中收到错误 我卡住了,帮我做什么 错误是 原因:java.lang.ClassCastException:org.apache.http.message.BasicHttpResponse无法转换为java.io.Reader 位于com.example.muhammad.try1.MainActivity$JSONAsyn

如何实现GSON@SerializedName我在
ModelClass ModelClass=new GSON().fromJson(响应,ModelClass.class)中收到错误
我卡住了,帮我做什么

错误是

原因:java.lang.ClassCastException:org.apache.http.message.BasicHttpResponse无法转换为java.io.Reader 位于com.example.muhammad.try1.MainActivity$JSONAsyncTask.doInBackground(MainActivity.java:300) 位于com.example.muhammad.try1.MainActivity$JSONAsyncTask.doInBackground(MainActivity.java:254)

我在DoInBackground中收到错误

    @Override
       protected Boolean doInBackground(String... urls) {
        try {

            //------------------>>

            HttpGet httpGet = new HttpGet(urls[0]);
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response = httpclient.execute(httpGet);
            int status = response.getStatusLine().getStatusCode();

            if (status == 200) {
                HttpEntity entity = response.getEntity();
                String data = EntityUtils.toString(entity);


                JSONArray jsonarray = new JSONArray(data);

                latLngList.clear();

                for (int i = 0; i < jsonarray.length(); i++) {
                                           ModelClass modelClass = new Gson().fromJson(response, ModelClass.class);

                    LatLng latLng = new LatLng(Double.parseDouble(modelClass.getLatitude()), Double.parseDouble(modelClass.getLongitude())); // Use your server's methods
                    latLngList.add(latLng);

                }


                return true;

            }

            //------------------>>

        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return false;


    }`
@覆盖
受保护的布尔doInBackground(字符串…URL){
试一试{
//------------------>>
HttpGet HttpGet=新的HttpGet(URL[0]);
HttpClient HttpClient=新的DefaultHttpClient();
HttpResponse response=httpclient.execute(httpGet);
int status=response.getStatusLine().getStatusCode();
如果(状态==200){
HttpEntity=response.getEntity();
字符串数据=EntityUtils.toString(实体);
JSONArray JSONArray=新的JSONArray(数据);
latLngList.clear();
for(int i=0;i>
}捕获(IOE异常){
e、 printStackTrace();
}捕获(JSONException e){
e、 printStackTrace();
}
返回false;
}`
    @Override
       protected Boolean doInBackground(String... urls) {
        try {

            //------------------>>

            HttpGet httpGet = new HttpGet(urls[0]);
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response = httpclient.execute(httpGet);
            int status = response.getStatusLine().getStatusCode();

            if (status == 200) {
                HttpEntity entity = response.getEntity();
                String data = EntityUtils.toString(entity);


                JSONArray jsonarray = new JSONArray(data);

                latLngList.clear();

                for (int i = 0; i < jsonarray.length(); i++) {
                                           ModelClass modelClass = new Gson().fromJson(response, ModelClass.class);

                    LatLng latLng = new LatLng(Double.parseDouble(modelClass.getLatitude()), Double.parseDouble(modelClass.getLongitude())); // Use your server's methods
                    latLngList.add(latLng);

                }


                return true;

            }

            //------------------>>

        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return false;


    }`
ModelClass modelClass = 
   new Gson().fromJson(jsonarray.getJSONObject(i).toString(), ModelClass.class);