I'm fairly new to C# at least when it comes to things like this, so I apologize for the little amount of code I have.
I have a class that called Project.cs that needs to be used to hold data objects that I get from a 3rd party API.
Here is the class:
//Project.cs
public sealed class Project
{
public String Id { get; set; }
public String Title { get; set; }
public String Url { get; set; }
}
The method that you see below, is supposed to get the data(JSON) from the 3rd party API.
This API returns a list of projects in JSON form.
Fortunately I only need to pick a few attributes from the API (Id, Title, and URL).
Unfortunately, I have no idea how to get pick those specific attributes from the JSON and turn them into a collection of type Project.
Here is what I have so far. I know it's sparse.
//ProjectSearch.cs
public IEnumerable<Project> GetProjects(String catId)
{
//Get the data from the API
WebRequest request = WebRequest.Create("http://research.a.edu/api/Catalogs('123')");
request.ContentType = "application/json; charset=utf-8";
WebResponse response = request.GetResponse();
//put each object found in the API into a Project object
var project = new Project();
}
So, now, I'm stuck. I don't know how to get all the objects from the API and put them into a collection of type Project. Do I need a loop? Or is there another type of way of doing?
Sample JSON from API:
{"odata.metadata":"http://research.a.edu/api/Catalogs/
$metadata#Catalogs /@Element", "odata.id":"http://research.a.edu/api/Catalogs
('123')",
"Id":"12345", "ParentID":"xxxx","Name":"Test1","Created":"1/1/2015","Modified":"2/1/2015","Deleted","0","URL":"http://yoursite/1",
('123')",
"Id":"7897", "ParentID":"xxxx","Name":"Test2","Created":"4/1/2015","Modified":"7/1/2015","Deleted","1","URL":"http://yoursite/2",
('123')",
"Id":"65335", "ParentID":"xxxx","Name":"Test3","Created":"7/1/2015","Modified":"9/1/2015","Deleted","0","URL":"http://yoursite/3"
}
I'm lost.
If anyone could clue me in, I'd be grateful.
Thanks!