标签:
httpClient(执行时都需要放进线程中):
try {
String path="路径";
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(path);
HttpResponse response = httpClient.execute(httpGet);
int code = response.getStatusLine().getStatusCode();
if(code==200){
InputStream is = response.getEntity().getContent();
ByteArrayOutputStream bos=new ByteArrayOutputStream();
int len;
byte[] by=new byte[1024];
while((len=is.read(by))!=-1){
bos.write(by,0,len);
}
String json=bos.toString();
//解析gson字符串
Gson gson=new Gson();
History history = gson.fromJson(json, History.class);
List<ArrayHis> his=history.array;
return his;
}
} catch (Exception e) {
e.printStackTrace();
}
标签:
原文地址:http://www.cnblogs.com/coins1/p/5391221.html