如何在微调器中填充响应。
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中填充storealias。
答案 0 :(得分: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