如何解决System.InvalidCastException:'指定的转换无效' Json API的Xamarin Spinner Array
在填充微调器数组时遇到问题,它表示转换无效。 您能帮我解决这个问题吗?
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>();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。