Null Pointer Exception-parsing Json With Gson Android
Hi i am trying to parse Json using gson library.My Json String is this { 'data': [ { 'atb_atestwebservice_cities': [ { 'id': '3',
Solution 1:
your Data.class is not properly write to get your json data parse in proper way .you need following structure for to get your all response.
you need to use following classes for get Result Data.
Gsongson=newGson();
Datadata= gson.fromJson(jsonString,Data.class);
Here is your Data class
public classData {
@SerializedName("data")
public List<ResultData> mResultData;
}
public classResultData {
@SerializedName("atb_atestwebservice_cities")
public List<City> mCityList;
@SerializedName("atb_atestwebservice_states")
public List<State> mStateList;
}
public classCity {
/*"id": "3",
"cities": "Ajmer",
"date": "2012-03-01 19:30:32"*/
@SerializedName("id")
public String id;
@SerializedName("cities")
public String mCitie;
@SerializedName("date")
public String mData;
}
public classState {
/*"id": "2",
"states": "goa",
"date": "2012-02-28 12:53:51"*/
@SerializedName("id")
public String id;
@SerializedName("states")
public String mState;
@SerializedName("date")
public String mDate;
}
All these class you need to add in your package.
Post a Comment for "Null Pointer Exception-parsing Json With Gson Android"