Retrofit返回Null值

时间:2017-02-10 17:51:32

标签: android networking retrofit

我是Android网络新手。我无法弄清楚为什么我为 phonone

获得空值

这是JSON数据的示例:

{
    "columns":{ <some data here> },
    "rows":[  
    {  
        "timestamp":"28/08/2016 14:11:46",
        "name":"Mohammed Sohail",
        "phoneno.":8142629002,
        "event-name":"Roadies",
        "branch":"IT",
        "year":3
    },
    {  
        "timestamp":"28/08/2016 14:13:03",
        "name":"Shaik Asaduddin",
        "phoneno.":8143026049,
        "event-name":"Ted talk",
        "branch":"IT",
        "year":3
    }
}

我能够获得行数组中的每个值,除了“phoneno”它给我的空值

这是我的课程

注册课程:

public class Registration  {
    private Columns columns;
    private List<Row> rows = null;
    private Map<String, Object> additionalProperties = new HashMap<String, Object>();

    public Columns getColumns() {
        return columns;
    }

    public void setColumns(Columns columns) {
        this.columns = columns;
    }

    public List<Row> getRows() {
        return rows;
    }

    public void setRows(List<Row> rows) {
        this.rows = rows;
    }

    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    public void setAdditionalProperty(String name, Object value) {
        this.additionalProperties.put(name, value);
    }


}

行类:

public class Row {

    private String timestamp;
    private String name;
    private String phoneno;
    private String eventName;
    private String branch;
    private String year;

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhoneno() {
        return phoneno;
    }

    public void setPhoneno(String phoneno) {
        this.phoneno = phoneno;
    }

    public String getEventName() {
        return eventName;
    }

    public void setEventName(String eventName) {
        this.eventName = eventName;
    }

    public String getBranch() {
        return branch;
    }

    public void setBranch(String branch) {
        this.branch = branch;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

}

这是我用来设置文本视图的

的适配器
public class RegistrationAdapter extends RecyclerView.Adapter<RegistrationAdapter.RegistrationViewHolder> {

    private List<Row> rows;
    private Context context;
    private int rowLayout;

    public RegistrationAdapter(List<Row> rows) {
        this.rows=rows;
    }


    @Override
    public RegistrationAdapter.RegistrationViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.registration_item_view, parent, false);
        return new RegistrationViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RegistrationViewHolder holder, int position) {

        holder.studentName.setText(rows.get(position).getName());
        holder.studentPhone.setText(String.valueOf(rows.get(position).getPhoneno()));
        holder.studentBranch.setText(rows.get(position).getBranch());
        holder.studentYear.setText(rows.get(position).getYear());
    }

    @Override
    public int getItemCount() {
        return rows.size();
    }

    public class RegistrationViewHolder extends RecyclerView.ViewHolder {

        LinearLayout studentLayout;
        TextView studentName;
        TextView studentPhone;
        TextView studentBranch;
        TextView studentYear;


        public RegistrationViewHolder(View itemView) {
            super(itemView);
            studentLayout=(LinearLayout)itemView.findViewById(R.id.studentLayout);
            studentName=(TextView)itemView.findViewById(R.id.studentName);
            studentPhone=(TextView)itemView.findViewById(R.id.studentPhoneNumber);
            studentBranch=(TextView)itemView.findViewById(R.id.studentBranch);
            studentYear=(TextView)itemView.findViewById(R.id.studentYear);

        }
    }

    public RegistrationAdapter( List<Row> rows, int rowLayout,Context context) {
        this.rows = rows;
        this.rowLayout = rowLayout;
        this.context = context;
    }
}

2 个答案:

答案 0 :(得分:1)

也许是一个错字,但在你的json中,你有&#34; phoneno。&#34;你的行类指定了phoneno。

答案 1 :(得分:0)

你可以使用jsonschema2pojo从json对象中生成类。