modle的buil.gradle文件中android根标签下 添加useLibrary 'org.apache.http.legacy'
/**
工具类
* httpClient-- apche 基金会维护的请求网络的工具;
*/
public class MainActivity extends AppCompatActivity { public String urlString = "http://api.expoon.com/AppNews/getNewsList/type/1/p/1"; private TextView lv; List<Tools.DataBean> list=new ArrayList<>(); Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); list= (List<Tools.DataBean>) msg.obj; lv.setText(list.get(0).getNews_summary()); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv = (TextView) findViewById(R.id.lv); new Thread(){ @Override public void run() { super.run(); //得到httpclient对象 DefaultHttpClient client = new DefaultHttpClient(); //封装get请求 HttpGet hg=new HttpGet(urlString); //获取返回的response try { HttpResponse response = client.execute(hg); //获取状态码 int statusCode = response.getStatusLine().getStatusCode(); if(statusCode==200){ //entiry 里面封装的数据; HttpEntity entity = response.getEntity(); //这个result就是json字符串,剩下的就是解析工作了; String s = EntityUtils.toString(entity); Gson g=new Gson(); Tools tools = g.fromJson(s, Tools.class); List<Tools.DataBean> data = tools.getData(); Message msg=new Message(); msg.obj=data; handler.sendMessage(msg); }else{ } } catch (IOException e) { e.printStackTrace(); } } }.start(); } }