I have some json returned form and API in the following format and I'm trying to pull the separate "items" into a list of items:
{"meta":{"page":1,"count":41,"pageCount":1,"totalCount":41},
"items":[
{
"agentId":"007",
"presence":{"since":"2020-06-25T18:42:41.871Z","name":"Ready","description":"Ready","eligibleForRouting":true},
"workload":{"since":"2020-06-29T13:08:38.666Z","calls":0,"semiLive":0,"nonLive":0},
"interaction":[]},
{
"agentId":"1000",
"presence":{"since":"2021-03-08T18:15:37.567Z","name":"ExtendedAway","description":"In Meeting","eligibleForRouting":false},
"workload":{"since":"2020-12-31T19:52:06.495Z","calls":0,"semiLive":0,"nonLive":0},
"interaction":[]},
{
"agentId":"1001",
"presence":{"since":"2021-03-29T15:39:19.401Z","name":"ExtendedAway","description":"In Meeting","eligibleForRouting":false},
"workload":{"since":"2021-03-04T19:46:10.092Z","calls":0,"semiLive":0,"nonLive":0},
"interaction":[]},
{
"agentId":"1002",
"presence":{"since":"2021-03-31T15:09:13.699Z","name":"Away","description":"Break","eligibleForRouting":false},
"workload":{"since":"2021-03-31T15:06:09.804Z","calls":0,"semiLive":0,"nonLive":0},
"interaction":[]},
{
"agentId":"1003",
"presence":{"since":"2021-03-31T14:28:52.187Z","name":"Ready","description":"Ready","eligibleForRouting":true},
"workload":{"since":"2021-03-31T15:19:25.908Z","calls":1,"semiLive":0,"nonLive":0},
"interaction":[{
"guid":"017888bc-5c0b-410a-a389-fac8f9423457",
"channelGuid":null,
"since":"2021-03-31T15:19:23.763Z",
"medium":"Phone",
"mediumManager":"VCC",
"direction":"Inbound",
"state":"Wrap",
"reason":null}]},
{
"agentId":"1004",
"presence":{"since":"2021-01-15T20:43:44.391Z","name":"ExtendedAway","description":"In Meeting","eligibleForRouting":false},
"workload":{"since":"2020-07-01T20:19:36.049Z","calls":0,"semiLive":0,"nonLive":0},
"interaction":[]},
{
"agentId":"1005",
"presence":{"since":"2021-03-31T15:03:30.458Z","name":"ExtendedAway","description":"Projects","eligibleForRouting":false},
"workload":{"since":"2021-03-31T13:33:22.917Z","calls":0,"semiLive":0,"nonLive":0},
"interaction":[]},
{
"agentId":"1006",
"presence":{"since":"2021-03-30T21:30:34.339Z","name":"LoggedOut","description":"Logged Out","eligibleForRouting":false},
"workload":{"since":"2021-03-30T20:30:17.244Z","calls":0,"semiLive":0,"nonLive":0},
"interaction":[]},
{
"agentId":"1007",
"presence":{"since":"2021-03-31T14:19:25.260Z","name":"Ready","description":"Ready","eligibleForRouting":true},
"workload":{"since":"2021-03-31T15:10:10.770Z","calls":1,"semiLive":0,"nonLive":0},
"interaction":[{
"guid":"017888b9-3108-467d-8c2f-a82c94100183",
"channelGuid":null,
"since":"2021-03-31T15:10:13.779Z",
"medium":"Phone",
"mediumManager":"VCC",
"direction":"Inbound",
"state":"Wrap",
"reason":null}]},
{
"agentId":"1008",
"presence":{"since":"2021-03-31T14:29:19.543Z","name":"Ready","description":"Ready","eligibleForRouting":true},
"workload":{"since":"2021-03-31T15:14:46.599Z","calls":1,"semiLive":0,"nonLive":0},
"interaction":[{
"guid":"017888bf-c715-4c18-b2af-e3bc52e90561",
"channelGuid":null,
"since":"2021-03-31T15:14:54.237Z",
"medium":"Phone",
"mediumManager":"VCC",
"direction":"Inbound",
"state":"Connected",
"reason":null}]}
}
I have custom classes as follows:
- public class AgentStatus
- {
- [JsonProperty("agentId")]
- public string AgentID { get; set; }
- [JsonProperty("presence")]
- public Presence Presence { get; set; }
- [JsonProperty("workload")]
- public Workload Workload { get; set; }
- [JsonProperty("interaction")]
- public Interaction Interaction { get; set; }
- }
- public class Presence
- {
- [JsonProperty("since")]
- public string Since { get; set; }
- [JsonProperty("name")]
- public string Name { get; set; }
- [JsonProperty("description")]
- public string Description { get; set; }
- [JsonProperty("eligibleForRouting")]
- public bool EligibleForRouting { get; set; }
- }
- public class Workload
- {
- [JsonProperty("since")]
- public string Since { get; set; }
- [JsonProperty("calls")]
- public string Calls { get; set; }
- [JsonProperty("semiLive")]
- public bool SemiLive { get; set; }
- [JsonProperty("nonLive")]
- public bool NonLive { get; set; }
- }
- public class Interaction
- {
- [JsonProperty("guid")]
- public string Guid { get; set; }
- [JsonProperty("channelGuid")]
- public string ChannelGuid { get; set; }
- [JsonProperty("since")]
- public string Since { get; set; }
- [JsonProperty("medium")]
- public string Medium { get; set; }
- [JsonProperty("mediumManager")]
- public string MediumManager { get; set; }
- [JsonProperty("direction")]
- public string Direction { get; set; }
- [JsonProperty("state")]
- public string State { get; set; }
- [JsonProperty("reason")]
- public string Reason { get; set; }
- }
I'm trying to deserialize with the following code:
- IRestResponse response = client.Execute(request);
- dynamic json = JsonConvert.DeserializeObject<List<AgentStatus>>(response.Content.ToString());
But get an error: "Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`"
I'm admittedly very new to working with JSON responses.