这是我的代码。我使用函数来检索列表,但它没有发送它。将函数返回给函数
public List<string> country_set()
{
mCountryUrl = new Uri ("http://xxxxxxx.wwww/restservice/country");
mList = new List<string>();
mCountry = new List<Country>();
WebClient client = new WebClient();
client.DownloadDataAsync (mCountryUrl);
client.DownloadDataCompleted += (sender, e) => {
RunOnUiThread (() => {
string json = Encoding.UTF8.GetString (e.Result);
mCountry = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Country>> (json);
Console.WriteLine (mCountry.Count.ToString());
int x = mCountry.Count;
for(int i=0; i< x ; i++)
{
mList.Add(mCountry[i].name);
}
});
};
return mList;
}
它引发异常。 请帮助我
你会得到哪些例外? – Chostakovitch
什么行引发异常? – bkribbs
除非它是android的设计模式,否则您怀疑您返回的是带有0个元素的列表,并派发一个线程将项添加到该列表中(这也不是线程安全的)。 – Rob