猿问

Restsharp 问题反序列化

我正在尝试反序列化一个 JSON,它从 API 调用中连续包含一系列“客户端”:


{"resource":[{"ClientID":1,"ClientName":"Name 1","ClientIntID":"TEST001","ClientCreatedDate":"2018-05-10 00:00:00"},{"ClientID":2,"ClientName":"Name 2","ClientIntID":"TEST002","ClientCreatedDate":"2018-05-10 03:10:47"},{"ClientID":3,"ClientName":"TestAPI","ClientIntID":"API001","ClientCreatedDate":"2018-05-10 03:30:14"},{"ClientID":4,"ClientName":"Postman","ClientIntID":"00POST","ClientCreatedDate":"2018-05-10 05:03:40"},{"ClientID":5,"ClientName":"Postman","ClientIntID":"00POST","ClientCreatedDate":"2018-05-10 05:04:28"},{"ClientID":6,"ClientName":"Postman","ClientIntID":"00POST","ClientCreatedDate":"2018-05-10 05:04:31"},{"ClientID":7,"ClientName":"Postman","ClientIntID":"00POST","ClientCreatedDate":"2018-05-10 05:10:32"},{"ClientID":8,"ClientName":"Postman","ClientIntID":"00POST","ClientCreatedDate":"2018-05-10 05:10:35"}]}

进入客户列表。


这是我的反序列化代码:


        IRestResponse<List<Client>> response = restClient.Execute<List<Client>>(request);

        var content = response.Content;

        var data = response.Data;


        //Trying to check output of each Client in List:

        foreach(Client c in data)

            {

                Console.WriteLine(c.ClientName);

            }

这是我的客户端类:


    public class Client

{

    public int ClientID { get; set; }

    public string ClientName { get; set; }

    public string ClientIntID { get; set; }

    public string ClientCreatedDate { get; set; }


}

我得到一个空列表,但是当我将代码更改为仅转换为一个客户端时,它正确地将第一个客户端存储在 JSON 响应中。


有小费吗?


偶然的你
浏览 183回答 1
1回答
随时随地看视频慕课网APP
我要回答