use of com.lzy.demo.model.ServerModel in project okhttp-OkGo by jeasonlzy.
the class RxCommonActivity method jsonRequest.
@OnClick(R.id.jsonRequest)
public void jsonRequest(View view) {
Subscription subscription = //
OkGo.post(Urls.URL_JSONOBJECT).headers("aaa", //
"111").params("bbb", //一定要注意这里的写法,JsonConvert最后的大括号千万不能忘记
"222").getCall(new JsonConvert<LzyResponse<ServerModel>>() {
}, //
RxAdapter.<LzyResponse<ServerModel>>create()).doOnSubscribe(new Action0() {
@Override
public void call() {
showLoading();
}
}).map(new Func1<LzyResponse<ServerModel>, ServerModel>() {
@Override
public ServerModel call(LzyResponse<ServerModel> response) {
return response.data;
}
}).observeOn(//
AndroidSchedulers.mainThread()).subscribe(new Action1<ServerModel>() {
@Override
public void call(ServerModel serverModel) {
//请求成功
dismissLoading();
handleResponse(serverModel, null, null);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
//请求失败
throwable.printStackTrace();
showToast("请求失败");
dismissLoading();
handleError(null, null);
}
});
addSubscribe(subscription);
}
Aggregations