2014-11-06 110 views
0

請幫助主... 如何從響應json創建微調?響應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"}]} 
+0

創建一個列表<>做,但我還沒有找到把適配器微調 – Ashadi 2014-11-06 04:24:11

+0

@Ashadi請在這裏發表您的代碼。 – 2014-11-06 04:24:43

+0

也許[這](http://stackoverflow.com/questions/2784081/android-create-spinner-programmatically-from-array)後可以幫助你, – 2014-11-06 04:28:24

回答

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