這是我的JSON:GSON解析安卓
{
"Curs": [
{
"ID": "AED",
"Name": "Dirhamul Emiratelor Arabe",
"Curs": "0.8503",
"Multiplier": "1",
"Data": "2011-02-09"
},
{
"ID": "AUD",
"Name": "Dolarul australian",
"Curs": "3.1572",
"Multiplier": "1",
"Data": "2011-02-09"
}
]
}
這是我的課:
public class Curs {
@SerializedName("ID")
public String id;
@SerializedName("Name")
public String nume;
@SerializedName("Curs")
public double crs;
@SerializedName("Multiplier")
public int mult;
@SerializedName("Data")
public Date data;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getNume() {
return nume;
}
public void setNume(String nume) {
this.nume= nume;
}
public void setCrs(double crs) {
this.crs=crs;
}
public double getCrs(){
return crs;
}
public void setMult(int mult) {
this.mult=mult;
}
public int getMult(){
return mult;
}
public void setData(Date data) {
this.data=data;
}
public Date getData(){
return data;
}
}
這是包含我的列表類:
public class CursList {
public static List<Curs> listaCurs;
public void setCursList(List <Curs> listaCurs) {
this.listaCurs = listaCurs;
}
public List<Curs> getCursList() {
return listaCurs;
}
}
我的分析是這樣的:
Gson gson=new Gson();
CursList listaCurs=gson.fromJson(Jsonresult,CursList.class);
當我訪問列表中我得到一個空pointer.What我做錯了什麼?
NPE在哪裏出現? –
當我嘗試像這樣訪問列表時發生錯誤:List listacurs = listaCurs.listaCurs; \t \t \t \t迭代器 iterator = null; \t \t iterator = listacurs.iterator(); \t \t而(iterator.hasNext()) \t \t { \t \t} –
發現如果listacurs爲空(或者,如果它是你從中得到了迭代器) –