2016-05-27 24 views
0

スピナーで応答を取り込む方法。スピナーにjson配列を取り込む方法

public void onResponse(Call<List<SelectStoresModelResponse>> call, Response<List<SelectStoresModelResponse>> response) { 
    if (response.isSuccess()) { 
      List<SelectStoresModelResponse> basicResponse = response.body(); 
    } 
} 

私のスピナーが

@Bind(R.id.spnselectstorevw) 
    Spinner SelectStores; 

である私のJSONデータは次のとおりです。

[ 
    { 
    "_id":"656456565646546542", 
    "storealias:""abc" 
    } 
] 

私は私のスピナーで "storealias" をしたいです。私のスピナーSelectStoresに店舗を登録する方法を教えてください。 Sppinerで

答えて

0

使用この

Spinner spinner; 
spinner = (Spinner) findViewById(R.id.spinner1) ; 
java.util.ArrayList<String> strings = new java.util.ArrayList<>(); 

Prase JSON

try { 
    JSONObject jsonRootObject = new JSONObject(strJson); 

    //Get the instance of JSONArray that contains JSONObjects 
    JSONArray jsonArray = jsonRootObject.optJSONArray("Employee"); 

    //Iterate the jsonArray and print the info of JSONObjects 
    for(int i=0; i < jsonArray.length(); i++){ 
     JSONObject jsonObject = jsonArray.getJSONObject(i); 


     String name = jsonObject.optString("storealias").toString(); 

     strings.add(name) ; 

    } 
    output.setText(data); 
    } catch (JSONException e) {e.printStackTrace();} 

設定データ

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
       android.R.layout.simple_spinner_item, strings); 
     spinner.setAdapter(adapter); 

ましょう

String response = { 
    "_id":"656456565646546542", 
    "storealias:""abc" 
    } 

JsonObject jsonObject = new JsonObject(response); 
jsonObject.get("storealias");    // will return abc 
+0

何Iここの従業員は? – dev

+0

@dev私の編集した答えを試してください –

関連する問題