我有这个应用程序,我试图将列表传递给另一个类。我不断收到错误
Cannot implicitly convert type 'System.Collections.Generic.List<eko_app.LoginForm.Business>' to 'System.Collections.Generic.List<eko_app.GlobalClass.Business>'
该列表是从 Json 生成的。
登录类
private void Connect()
{
try
{
serverUrl = "https://eko-app.com/Users/login/username:" + usernameEntered + "/password:" + passwordEntered + ".json";
var w = new WebClient();
var jsonData = string.Empty;
// make the login api call
jsonData = w.DownloadString(serverUrl);
if (!string.IsNullOrEmpty(jsonData))
{
// deserialize the json to c# .net
var response = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(jsonData);
// Get the sessionId
GlobalClass.SessionId = string.Empty;
GlobalClass.SessionId = response.response.SessionId;
if (GlobalClass.SessionId != null)
{
var businesses = response.response.Businesses;
GlobalClass.Username = "";
GlobalClass.Username = usernameEntered;
GlobalClass.Businesses = null;
GlobalClass.Businesses = businesses; **<-----error thrown here**
HomeForm homeForm = new HomeForm();
this.Hide();
homeForm.Show();
}
else
{
Console.WriteLine("Login failed");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private class Business
{
public string businessID { get; set; }
public string businessName { get; set; }
}
private class Response
{
[JsonProperty("sessionId")]
public string SessionId { get; set; }
[JsonProperty("businesses")]
public List<Business> Businesses { get; set; }
}
private class Messages
{
public string sessionId { get; set; }
public List<Business> businesses { get; set; }
}
private class RootObject
{
public Response response { get; set; }
public Messages messages { get; set; }
}
我还有另一门课:全球课
namespace eko_app
{
static class GlobalClass
{
...some code
public class Business
{
private string businessID { get; set; }
private string businessName { get; set; }
}
private static List<Business> businesses = null;
public static List<Business> Businesses
{
get { return businesses; }
set { businesses = value; }
}
}
}
我究竟做错了什么?错误在第一堂课中抛出 GlobalClass.Businesses = businesses;