新实施RxJava2并进行了改造,实现了所有内容,并希望将结果作为JSONObeject
Map<String, String> requestBody = new HashMap<>();
requestBody.put("username", "xyz");
requestBody.put("password", "abc");
Single<ResponseBody> singleResponse = myService.loginWithParam(requestBody);
singleResponse.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<ResponseBody>() {
@Override
public void onSuccess(ResponseBody response) {
response // this needs to be converted JsonObject
loginResponse(response);
}
@Override
public void onError(Throwable e) {
System.out.println(e.getMessage());
}
});
ResponseBody响应如何将其转换为Json对象,无法在线找到任何链接。
答案 0 :(得分:1)
最简单的方法是直接将其作为模型对象,改造可以将json自动解析为模型对象:https://stackoverflow.com/a/31112346/1310343