2017-02-10 82 views
0

我是新来的Android联网。我无法弄清楚,为什么我得到空值的phonone改造返回NULL值

这是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); 
    } 


} 

Row类:

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; 
    } 
} 
+0

需要@expose领域中的POJO – Blackbelt

+0

但我能得到的值的其余部分,而无需使用@揭露,它是强制性的? –

+0

请检查您的JSON数据,我可以看到一个点(。)在“PHONENO。”,这是一场错误错字?如果不是,那么你可以检查是否导致问题。 –

回答

1

也许是一个错字,但在你的JSON你有“PHONENO。”你的行类指定了phoneno。

+0

但“电话号码。”你在json索引的末尾有一个点。但是在你的类变量中缺少那个点。 –

+0

我可以在你的JSON看看是不是“PHONENO”的问题 – krlos77

+0

感谢您的帮助的问题是固定的,我错过了点 –

0

您可以使用jsonschema2pojo从JSON对象genenare类。