Android 如何实现GSON@SerializedName我在DoInBackground中收到错误
如何实现GSON@SerializedName我在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
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);