I have this JSON object below
{
"Metadata": {
"TotalRecords": 12,
"CurrentPageSize": 2,
"CurrentPage": 1,
"TotalPages": 2
},
"Results": [
{
"Id": 1,
"OwnerId": "3be73a87-a977-467a-84c0",
"OwnerName": "AV",
"CategoryId": 3,
"CategoryName": "User 1 Physical",
"Name": "User 1 Speed",
"Description": null,
"NoOfMinutes": 15,
"CreatedDate": "2019-09-22T03:34:56.4033333",
"ModifiedDate": null
},
{
"Id": 2,
"OwnerId": "3be73a87-a977-467a-84c0",
"OwnerName": "AV",
"CategoryId": 1,
"CategoryName": "User 1 Technique",
"Name": "User 1 tech",
"Description": null,
"NoOfMinutes": 60,
"CreatedDate": "2019-09-22T03:34:56.4033333",
"ModifiedDate": null
}
]
}
and using JSON2Csharp:
public class Metadata
{
public int TotalRecords { get; set; }
public int CurrentPageSize { get; set; }
public int CurrentPage { get; set; }
public int TotalPages { get; set; }
}
public class Result
{
public int Id { get; set; }
public string OwnerId { get; set; }
public string OwnerName { get; set; }
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public string Name { get; set; }
public object Description { get; set; }
public int NoOfMinutes { get; set; }
public DateTime CreatedDate { get; set; }
public object ModifiedDate { get; set; }
}
public class RootObject
{
public Metadata Metadata { get; set; }
public List<Result> Results { get; set; }
}
How do mapped this entire thing NOT just Result (refer as Activities) into the Xamarin API service for getting the data and return?
This is the original API before changing the entire structure of the data:
public async List<Activities> GetActivities()
{
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", "ACCCESS TOKEN HERE");
var response = httpClient.GetStringAsync("https://XXX.azurewebsites.net/api/v1/Activities");
JsonConvert.DeserializeObject<Activities>(response);
}