I want to parse the following Json response:
{
"message": "string",
"errorCode": "string",
"totalSize": 0,
"offset": 0,
"done": true,
"nextRecordsUrl": "string",
"records": [
{
"id": "string",
"name": "string",
"external_ID_vod__c": "string",
"vExternal_Id_vod__c": "string"
}
]
}
**Note that there are multiple 'record'
The class I am using to deserialize the Json response is:
public class Products
{
public string message { get; set; }
public string errorCode { get; set; }
public int totalSize { get; set; }
public int offset { get; set; }
public bool done { get; set; }
public string nextRecordsUrl { get; set; }
public List<RecordProduct> records { get; set; }
}
public class RecordProduct
{
public string id { get; set; }
public string name { get; set; }
public string external_ID_vod__c { get; set; }
public string vExternal_Id_vod__c { get; set; }
}
The code that is calling the API:
public void getAllProductInfo()
{
RestClient client = new RestClient("blahblahblah/");
RestRequest request = new RestRequest("/api/Products", Method.GET);
string securityToken = getBearerToken();
request.AddHeader("Accept", "application/json");
request.AddHeader("Authorization", "Bearer " + securityToken);
IRestResponse<JsonResponseSetup.Datum.Products> response = client.Execute<JsonResponseSetup.Datum.Products>(request);
var res = response.Data.records;
res.ForEach(Console.WriteLine);
}
When I execute the last line: res.ForEach(Console.WriteLine); I do not get the records to print.