System.InvalidCastException:'Specified cast is not valid.' 来自 Json API 的 Xamarin Spinner 数组
System.InvalidCastException: 'Specified cast is not valid.' Xamarin Spinner Array from Json API
我在填充微调器数组时遇到问题,它说转换无效。
你能帮我解决这个问题吗?
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: 'Specified cast is not valid.' 用数组填充适配器时。
尝试改变
ArrayList items = new ArrayList();
至
List<string> items = new List<string>();
我在填充微调器数组时遇到问题,它说转换无效。 你能帮我解决这个问题吗?
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: 'Specified cast is not valid.' 用数组填充适配器时。
尝试改变
ArrayList items = new ArrayList();
至
List<string> items = new List<string>();