响应JSON到适配器微调器

时间:2014-11-06 03:40:58

标签: android json spinner android-spinner

请帮助师父...... 如何从响应json创建微调器?

这个例子响应json

[{"kode":"I5","hrg":5700,"nom":"5000","ket":"IM3 REG 5000"},{"kode":"ISG5","hrg":5700,"nom":"5000","ket":"IM3 GPRS ALTERNATIF 5000"},{"kode":"ISS5","hrg":5700,"nom":"5000","ket":"IM3 SMS ALTERNATIF 5000"},{"kode":"IS5","hrg":5700,"nom":"5000","ket":"IM3 REG ALTERNATIF 5000"},{"kode":"I5S","hrg":5700,"nom":"5000","ket":"IM3 SMS 5000"},{"kode":"ITG5","hrg":5700,"nom":"5000","ket":"IM3 GPRS 5000"},{"kode":"ITG10","hrg":10700,"nom":"10000","ket":"IM3 GPRS 10000"},{"kode":"I10","hrg":10700,"nom":"10000","ket":"IM3 10000"},{"kode":"I10S","hrg":10700,"nom":"10000","ket":"IM3 SMS 250 10000"},{"kode":"IS10","hrg":10700,"nom":"10000","ket":"IM3 REG ALTERNATIF 10000"},{"kode":"ISG10","hrg":10700,"nom":"10000","ket":"IM3 GPRS ALTERNATIF 10000"},{"kode":"ISS10","hrg":10700,"nom":"10000","ket":"IM3 SMS ALTERNATIF 10000"},{"kode":"I20","hrg":20400,"nom":"20000","ket":"IM3 REG 20000"},{"kode":"I25","hrg":25200,"nom":"25000","ket":"IM3 25000"},{"kode":"I25S","hrg":25400,"nom":"25000","ket":"IM3 SMS 1667 25000"},{"kode":"ITG25","hrg":25400,"nom":"25000","ket":"IM3 GPRS 25000"},{"kode":"I30","hrg":30400,"nom":"30000","ket":"IM3 REG 30000"},{"kode":"I50","hrg":49425,"nom":"50000","ket":"IM3 50000"},{"kode":"I100","hrg":98500,"nom":"100000","ket":"IM3 100000"}]}

1 个答案:

答案 0 :(得分:0)

try this code to get  the data


class ListData
{
String kode;
String hrg;
Strring nom;
String ket;

}

String jsonresult=[{"kode":"I5","hrg":5700,"nom":"5000","ket":"IM3 REG 5000"},{"kode":"ISG5","hrg":5700,"nom":"5000","ket":"IM3 GPRS ALTERNATIF 5000"},{"kode":"ISS5","hrg":5700,"nom":"5000","ket":"IM3 SMS ALTERNATIF 5000"},{"kode":"IS5","hrg":5700,"nom":"5000","ket":"IM3 REG ALTERNATIF 5000"},{"kode":"I5S","hrg":5700,"nom":"5000","ket":"IM3 SMS 5000"},{"kode":"ITG5","hrg":5700,"nom":"5000","ket":"IM3 GPRS 5000"},{"kode":"ITG10","hrg":10700,"nom":"10000","ket":"IM3 GPRS 10000"},{"kode":"I10","hrg":10700,"nom":"10000","ket":"IM3 10000"},{"kode":"I10S","hrg":10700,"nom":"10000","ket":"IM3 SMS 250 10000"},{"kode":"IS10","hrg":10700,"nom":"10000","ket":"IM3 REG ALTERNATIF 10000"},{"kode":"ISG10","hrg":10700,"nom":"10000","ket":"IM3 GPRS ALTERNATIF 10000"},{"kode":"ISS10","hrg":10700,"nom":"10000","ket":"IM3 SMS ALTERNATIF 10000"},{"kode":"I20","hrg":20400,"nom":"20000","ket":"IM3 REG 20000"},{"kode":"I25","hrg":25200,"nom":"25000","ket":"IM3 25000"},{"kode":"I25S","hrg":25400,"nom":"25000","ket":"IM3 SMS 1667 25000"},{"kode":"ITG25","hrg":25400,"nom":"25000","ket":"IM3 GPRS 25000"},{"kode":"I30","hrg":30400,"nom":"30000","ket":"IM3 REG 30000"},{"kode":"I50","hrg":49425,"nom":"50000","ket":"IM3 50000"},{"kode":"I100","hrg":98500,"nom":"100000","ket":"IM3 100000"}]};
ArrayList<ListData> listdata=new ArrayList<ListData>();
if(jsonresult!=null)
{
JsonArray array=new JsonArray(jsonresult);
if(jsonresult.length()>0)
{
for(int i=0;i<jsonresult.length();i++)
{

JsonObject object=array.get(i);
Listdata data=new Listdata();
String kode=object.getString("kode");
data.kote=kote;
String hrg=object.getString("hrg");
data.hrg=hrg;
String nom=object.getString("nom");
data.nom=nom;
String ket=object.getString("ket");
data.ket=ket;
listdata.add(data);
}

}

}

Use the arraylist in adapter for spinner according to your requirement