i have json data with two type of values. in first only one element will get inserted into dropdown list and in other multiple items can be inserted into dropdown list
JS :
var data =
{
"GETBILLERRESPONSE":
{
"RESPONSECODE":"0","RESPONSEMESSAGE":"Success","BILLERS":
{
"BILLER":{
"@ID":"6","@EIDENFORCED":"FALSE","@ISGETBALANCE":"TRUE","#text":"POP CORN MANIA","SERVICES":null
}
}
}
};
var data1 = {
"GETBILLERRESPONSE":
{
"RESPONSECODE":"0","RESPONSEMESSAGE":"Success","BILLERS":
{
"BILLER":
[
{
"@ID":"1","@EIDENFORCED":"TRUE","@ISGETBALANCE":"TRUE","#text":"Mumbai Bill Payment","SERVICES":{
"SERVICE":
[
{
"@ID":"1","#text":"Bill Payment"
},
{
"@ID":"2","#text":"Fine Payment"
}
]
}
},
{
"@ID":"7","@EIDENFORCED":"FALSE","@ISGETBALANCE":"TRUE","#text":"Delhi Bill Payment","SERVICES":null
},
{
"@ID":"23","@EIDENFORCED":"FALSE","@ISGETBALANCE":"TRUE","#text":"Chennai Bill Payment","SERVICES":null
}
]
}
}
};
var ResponseMessage = data1.GETBILLERRESPONSE.RESPONSEMESSAGE;
if (ResponseMessage == "Success")
{
var k=0;
var Html = "<option value=\"-1\">" + "Please select a payee." + "</option>";
var lenforbillers = data1.GETBILLERRESPONSE.BILLERS.BILLER.length;
var objforbillers = data1.GETBILLERRESPONSE.BILLERS.BILLER;
for (k = 0; k < lenforbillers; k++)
{
Html += "<option value=\"" + (objforbillers[k]['@ID']) + "\">" + (objforbillers[k]['#text']) + "</option>";
}
$("#dlInstantPayPayeee").html(Html);
}
My questions :
- if there is only one element in json nested list why cant i retrieve it by using array index[0] ?
- My for loop code works for
data1but not fordataasdatacontains only one element - how can i write only one piece of code which will crate drop down list irrespective of nested element in json
Fiddle : http://jsfiddle.net/E7zhK/3/