问题描述
在填充微调器数组时遇到问题,它表示转换无效。 您能帮我解决这个问题吗?
private async void getplant()
{
string url = "http://localhost/VMSAPINEW2/MasterData/getplantlist";
JsonValue json = await FetchWeatherAsync(url);
string temp = "";
ArrayList items = new ArrayList();
for (int i = 0; i < json.Count; i++)
{
temp = json[i]["plantName"].ToString();
items.Add(temp);
}
var adapter = new ArrayAdapter<string>(this,Android.Resource.Layout.SimpleSpinnerItem,(IList<string>)items);
spinnerPlantNormal.Adapter = adapter;
}
项目的结果是
item[0] "\"SBM - BIKE\""
item[1] "\"SBM - ROD\""
和错误 System.InvalidCastException:“指定的转换无效。” 当用数组填充适配器时。
解决方法
尝试改变
ArrayList items = new ArrayList();
到
List<string> items = new List<string>();