Reputation: 568
I am using an asp.net api to query from my xamarin app to SQL Server. Below is how I am querying the API, and setting up the return type, but I am getting an error of
Can not convert List to List
What do I need to change in my code so that this will execute as desired?
public List<string> GetApprovalGrid()
{
string URI = "XXXXXXX/api/Xamarin/properties";
using (var webClient = new System.Net.WebClient())
{
var json = webClient.DownloadString(URI);
var message = JsonConvert.DeserializeObject<List<string>>(json);
return message;
}
}
public class ApproveUsers
{
public int ID { get; set; }
public string fname { get; set; }
public string lname { get; set; }
public string phone { get; set; }
public string company { get; set; }
public string approveduser { get; set; }
}
private void LoadApproveUserGrid()
{
List<ApproveUsers> ApprovedUser = new List<ApproveUsers>();
//this line throws the error
ApprovedUser = dal.GetApprovalGrid();
//more code here
}
Upvotes: 0
Views: 77
Reputation: 1110
ApprovedUser is of type List<ApproveUsers>
but GetApprovalGrid() returns List<string>
EDIT:
JsonConvert.DeserializeObject<List<ApproveUsers>>(json);
if your json is correctly formatted
EDIT2: you need to change the method signature to this too:
public List<ApproveUsers> GetApprovalGrid()
Upvotes: 1