/** * Created by David Zheng on 2016/3/30. * * Qq:986945193 * * 微博:http://weibo.com/mcxiaobing */
/** * 异步获取到数据 开启了子线程 * * 若是同步只需将enqueue 改为execute即可 * * @return */ public String getUrlfromJson() { OkHttpClient mHttpClient = new OkHttpClient(); Request request = new Request.Builder().url(url) .build(); mHttpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { //加载失败 } @Override public void onResponse(Response response) throws IOException { //成功获取数据 if (response.isSuccessful()){ String json = response.body().toString(); Log.d("mainai", "onResponse() returned: " + json); } } }); return url; }