0

我需要使用 RestSharp 阅读以下代码。我的问题是如何使数组具有正确的结构。我需要如何设置将包含该对象的类以使其正常工作?

我想反序列化 AcUserInfo 类型列表中的对象“0”和“1”。

非常感谢。安德烈亚

{
   "0":{
      "id":"2",
      "subscriberid":"2",
      "cdate":"2012-09-28 16:49:06",
      "sdate":"2012-09-28 16:49:06",
      "first_name":"Al",
      "last_name":"",
      "email":"test@verizon.net"
   },
   "1":{
      "id":"29",
      "subscriberid":"29",
      "cdate":"2012-10-02 15:08:29",
      "sdate":"2012-10-02 15:08:29",
      "first_name":"Mark",
      "last_name":"",
      "email":"test2@verizon.net"
   },
   "result_code":1,
   "result_message":"Success: Something is returned",
   "result_output":"json"
}

这是我创建的课程:

public class SubscriberList {
    public int result_code { get; set; }
    public string result_message { get; set; }
    public string result_output { get; set; }
    public List<AcUserInfo> row { get; set; }

    SubscriberList(){
        row = new List<AcUserInfo>();
    }
}
4

1 回答 1

0

您的 JSON 数据不包含数组,因此无法反序列化为 List<>。

将您的 JSON 转换为以下内容:

{
  [{
  "id":"2",
  "subscriberid":"2",
  "cdate":"2012-09-28 16:49:06",
  "sdate":"2012-09-28 16:49:06",
  "first_name":"Al",
  "last_name":"",
  "email":"test@verizon.net"
  },
  {
  "id":"29",
  "subscriberid":"29",
  "cdate":"2012-10-02 15:08:29",
  "sdate":"2012-10-02 15:08:29",
  "first_name":"Mark",
  "last_name":"",
  "email":"test2@verizon.net"
  }],
  "result_code":1,
  "result_message":"Success: Something is returned",
  "result_output":"json"
}

或者,如果您始终只有“0”和“1”元素,请更改您的 SubscriberList 类以匹配它。

于 2012-10-12T09:31:21.457 回答