Reputation: 81
I'm having a problem displaying the data from the Get Request to the MVC Controller. I want to get my data from Kanbanize API and display it on my local app. I'm getting Status 200 OK, but when I want to add it in my controller and view something is messing up and I can't understand what.
This is my Get Request with Status Code 200 OK:
List<Board> boards = null;
string response = string.Empty;
var url = "https://<subdomain>.kanbanize.com/api/v2/boards/4";
var httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Method = "GET";
httpRequest.Headers.Add("apikey", "");
httpRequest.ContentType = "application/json";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
response = streamReader.ReadToEnd();
}
httpResponse.Close();
boards = Deserialize<List<Board>>(response);
return View(boards);
}
public static T Deserialize<T>(string jsonData)
{
JsonSerializer json = new JsonSerializer();
return json.Deserialize<T>(new JsonTextReader(new StringReader(jsonData)));
}
From here I'm getting the info that I want to display, but after that in the controller everything is getting really messy. Can anyone tell me what am I doing wrong and how is the proper way to do it. Thanks in advance!
Upvotes: 0
Views: 638
Reputation: 164
The response to https://<subdomain>.kanbanize.com/api/v2/boards/4
returns a single board detail and not a list.
Instead of declaring a list of Board, declare a single instance and try again please.
Upvotes: 1