Trying to get data for POST method Retrofit

前端 未结 1 553
南旧
南旧 2021-01-21 14:32

Im trying to get username when I try to login to wev service.I need this username to check did I this right or no.But have NPE when try to get data,but when I just make Toast wi

相关标签:
1条回答
  • 2021-01-21 14:58

    SignInResults.java // Model class

    clas SignInResults {
       public Boolean status;
       public Auth auth;
       public User user;
    }
    

    User.java //User Model

    public class User {
        public String userId;
        public String username;
        public String avatar;
    }
    

    checkout this code in onResponse function

    if (response.isSuccess()) {
    
        SignInResults results = response.body();
    
        if(results != null) {
    
            String userName = results.user.username;
    
            Log.d("User Name ==>> ", userName);
    
        }
    
    } else {
        // Do whatever you want if API is unsuccessful.
    }
    
    0 讨论(0)
提交回复
热议问题