2016-05-27 37 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中填充存儲區。

回答

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();} 

坐落在Sppiner數據

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

我這裏的員工? – dev

+0

@dev試試我編輯的答案 –