导依赖包
compile 'com.squareup.okhttp:okhttp:2.4.0'
//创建OkHttpClient对象
OkHttpClient mok = new OkHttpClient();
//创建一个Request
final Request request = new Request
.Builder()
.url("放接口")
.build();
mok.newCall(request).enqueue(new Callback() {
String re;
@Override
public void onFailure(Request request, IOException e) {
}
@Override
public void onResponse(final Response response) throws IOException {
re = response.body().string();
runOnUiThread(new Runnable() {
@Override
public void run() {
Data data = new Gson().fromJson(re, Data.class);
}
});
}
});