【问题标题】:How to use in retrofit 1.9 in a property property?如何在属性属性中使用改造 1.9?
【发布时间】:2016-09-19 09:53:40
【问题描述】:

如何在( "Name": "AccountManager") 属性中使用改造

[  {
    "ID": 3065,
    "UserName": "test",
    "Email": "test",
    "Password": "test",
    "SkypeID": "test",
    "GoogleHangout": "test",
    "Inactive": false,
    "HasHoursRegistered": false,
    "CreatedBy": null,
    "EditedBy": null,
    "WebRole": null,
    "ProjectsDtos": null,
    "RegHoursDtos": null,
    "CustomersDtos": null,
    "RolesDtos": \[
      {
        "ID": 1,
        "Name": "AccountManager",
        "Prices": null,
        "Users": null,
        "UsersRolesProjects": null
      }
    \],
    "UsersRolesProjectsDtos": null
  }
]

【问题讨论】:

    标签: android json retrofit


    【解决方案1】:

    你需要创建一个对象来处理响应,在这个对象里面,你需要一个对象列表RolesDtos(因为是一个对象数组)

    public class RolesDtos{
      int ID;
      String Name;    
      String prices;
      String Users;
      ...
      setters and getters
    }
    
    public class ResponseObject{
      int ID;
      String userName;    
      String email;
      String password;
      String skypeId;
      ...
      List<RolesDtos> rolesDtos; // <- here 
      ...
      setters and getters
    }
    

    要获得"Name": "AccountManager",您必须执行以下操作:

    ResponseObject responseObject = new ResponseObject();
    responseObject.getRolesDtos().get(0).getName(); 
    

    get(0) 是数组的位置,所以必须对数组进行迭代。现在在请求中你必须做这样的事情:

    @GET("url")
    Call<ResponseObject> theRequest(...)
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:
             How i can set here the  "Name": "AccountManager" property?  
       User user = getItem(position);
      
      
                      if (user != null) {
                      TextView tvUserId = (TextView) v.findViewById(R.id.user_id);
                      TextView tvUserName = (TextView) v.findViewById(R.id.user_name);
                      TextView tvEmail=(TextView)v.findViewById(R.id.email);
                      TextView tvRole=(TextView)v.findViewById(R.id.userRole);
      
                      tvUserId.setText( Integer.toString(user.ID));
                      tvUserName.setText(user.UserName);
                      tvEmail.setText(user.Email);
                    //  tvRole.setText(user.getRolesDtos().toArray(1));
      

      【讨论】:

        猜你喜欢
        • 2013-08-01
        • 1970-01-01
        • 2021-07-11
        • 2019-07-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-25
        • 1970-01-01
        相关资源
        最近更新 更多