2017-02-10 63 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類。