How to read this json data from server
{
"DS": {
"LST": [
{
"OID": 1,
"OCD": "1",
"OPE": "AIRCEL",
"IPH": "Images/provider/aircelsm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 2,
"OCD": "3",
"OPE": "AIRTEL",
"IPH": "Images/provider/airtelsm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 22,
"OCD": "BSR",
"OPE": "BSNL SPL RECHARGE",
"IPH": "",
"MIL": 0,
"MXL": 0
},
{
"OID": 4,
"OCD": "4",
"OPE": "BSNL Topup",
"IPH": "Images/provider/bsnlsm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 6,
"OCD": "5",
"OPE": "DOCOMO",
"IPH": "Images/provider/docomosm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 7,
"OCD": "6",
"OPE": "IDEA",
"IPH": "Images/provider/ideasm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 8,
"OCD": "7",
"OPE": "MTS",
"IPH": "Images/provider/mtssm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 5,
"OCD": "8",
"OPE": "RELAINCE",
"IPH": "Images/provider/reliancesm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 3,
"OCD": "9",
"OPE": "VODAFONE",
"IPH": "Images/provider/vodafonesm.jpg",
"MIL": 10,
"MXL": 10
}
],
"LST1": [
{
"OID": 10,
"OCD": "0",
"OPE": "AIRTEL DTH",
"IPH": "Images/provider/airtelsm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 11,
"OCD": "0",
"OPE": "BIGTV",
"IPH": "Images/provider/aircelsm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 12,
"OCD": "0",
"OPE": "DISH TV",
"IPH": "Images/provider/dishtvsm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 9,
"OCD": "0",
"OPE": "SUN DIRECT",
"IPH": "Images/provider/sundirectsm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 13,
"OCD": "0",
"OPE": "TATA SKY",
"IPH": "Images/provider/tataskysm.jpg",
"MIL": 10,
"MXL": 10
},
{
"OID": 14,
"OCD": "0",
"OPE": "VIDEOCON DTH",
"IPH": "Images/provider/videoconsm.jpg",
"MIL": 10,
"MXL": 10
}
]
}
}
For reading the above json type i used the method is given below
Gson gson = new Gson();
Type listType = new TypeToken<List<SpinnerMenuItems>>(){}.getType();
List<SpinnerMenuItems> selectedNetwork = gson.fromJson(gson.toJson(result.getResult()), listType);
settingDropDown(selectedNetwork);
Actually my problem is to read the json array from the json object and the json array are viewed in a listview by using custom adapter. I don't know how to read this.
For reading the json object i used the following model class
public class SpinnerMenuItems {
@SerializedName("LST")
String zeroList;
@SerializedName("LST1")
String firstList;
public String getZeroList() {
return zeroList;
}
public void setZeroList(String zeroList) {
this.zeroList = zeroList;
}
public String getFirstList() {
return firstList;
}
public void setFirstList(String firstList) {
this.firstList = firstList;
}
}
The above model class is to read the list inside the json object.
The below model class is to read the json array which is placed inside the json object
public class ListZero {
@SerializedName("IPH")
String images;
@SerializedName("OID")
String oid;
@SerializedName("OPE")
String ope;
@SerializedName("OCD")
String ocd;
@SerializedName("MIL")
String mil;
public String getMxl() {
return mxl;
}
public void setMxl(String mxl) {
this.mxl = mxl;
}
public String getMil() {
return mil;
}
public void setMil(String mil) {
this.mil = mil;
}
public String getOcd() {
return ocd;
}
public void setOcd(String ocd) {
this.ocd = ocd;
}
public String getOpe() {
return ope;
}
public void setOpe(String ope) {
this.ope = ope;
}
public String getOid() {
return oid;
}
public void setOid(String oid) {
this.oid = oid;
}
public String getImages() {
return images;
}
public void setImages(String images) {
this.images = images;
}
@SerializedName("MXL")
String mxl;
}
Please help me how to read the json array which is placed inside the json object. In my case i need to read the only one json array list and view the list in a listview. How to read the json array.
See Question&Answers more detail:
os