如何在 C# 中序列化 JSON?

How to serialize JSON in C#?

无法在 C# 中序列化 json

我在 C# 中的代码是 -

string json = "contains json";
YahooContactsData contacts1 = JsonConvert.DeserializeObject<YahooContactsData>(json)

我用过的类-

public class YahooContactsData
{
    public YContacts contacts; 
}
public class YContacts
{
    public YContact contact { get; set; }
}
public class YContact
{
    public List<YFields> fields { get; set; }
}
public class YFields
{
    public int id { get; set; }
    public string type { get; set; }
}

Json 是 -

{"contacts":{"contact":[{"isConnection":false,"id":22,"fields":[{"id":44,"type":"yahooid","value":"angel2pretty123","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-02-21T18:47:00Z","created":"2009-02-03T17:54:27Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/22/yahooid/44"},{"id":16777269,"type":"nickname","value":"angel2pretty123","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-02-21T18:47:00Z","created":"2009-02-21T18:47:00Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/22/nickname/16777269"}],"categories":[],"error":0,"restoredId":0,"created":"2009-02-03T17:54:27Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/22"},{"isConnection":false,"id":5,"fields":[{"id":17,"type":"name","value":{"givenName":"Mira","middleName":"","familyName":"Grover","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","flags":[],"categories":[],"updated":"2008-11-29T12:52:40Z","created":"2008-11-29T12:52:40Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/5/name/17"},{"id":16,"type":"yahooid","value":"mira_grover@ymail.com","editedBy":"OWNER","flags":[],"categories":[],"updated":"2008-11-29T12:52:40Z","created":"2008-11-29T12:52:23Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/5/yahooid/16"}],"categories":[],"error":0,"restoredId":0,"created":"2008-11-29T12:52:23Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/5"},{"isConnection":false,"id":28,"fields":[{"id":52,"type":"name","value":{"givenName":"deepshikha","middleName":"","familyName":"gupta","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-02-16T20:45:32Z","created":"2009-02-16T20:45:32Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/28/name/52"},{"id":51,"type":"yahooid","value":"deepshikha_friendly","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-02-16T20:45:32Z","created":"2009-02-14T14:18:19Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/28/yahooid/51"}],"categories":[],"error":0,"restoredId":0,"created":"2009-02-14T14:18:19Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/28"},{"isConnection":false,"id":21,"fields":[{"id":38,"type":"yahooid","value":"kirtimine","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-28T20:28:51Z","created":"2009-01-28T20:28:51Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/21/yahooid/38"}],"categories":[],"error":0,"restoredId":0,"created":"2009-01-28T20:28:51Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/21"},{"isConnection":false,"id":23,"fields":[{"id":46,"type":"name","value":{"givenName":"Mehwish","middleName":"","familyName":"Maqsood","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-02-08T15:33:34Z","created":"2009-02-08T15:33:34Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/23/name/46"},{"id":45,"type":"yahooid","value":"wish_cuty","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-02-08T15:33:34Z","created":"2009-02-08T15:33:16Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/23/yahooid/45"}],"categories":[],"error":0,"restoredId":0,"created":"2009-02-08T15:33:16Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/23"},{"isConnection":false,"id":32,"fields":[{"id":57,"type":"name","value":{"givenName":"Tammy","middleName":"","familyName":"Masselli","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-03-29T11:11:36Z","created":"2009-03-29T11:11:36Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/32/name/57"},{"id":58,"type":"guid","value":"WD46RWRPX2NDOJXH6RB6PGZZTY","editedBy":"OWNER","flags":[],"isConnection":false,"categories":[],"updated":"2014-09-10T10:48:05Z","created":"2009-03-29T11:11:36Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/32/guid/58"}],"categories":[],"error":0,"restoredId":0,"created":"2009-03-29T11:11:36Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/32"},{"isConnection":false,"id":16777247,"fields":[{"id":16777272,"type":"yahooid","value":"mississippinymph6709","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-03-06T21:34:59Z","created":"2009-03-06T21:34:59Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/16777247/yahooid/16777272"}],"categories":[],"error":0,"restoredId":0,"created":"2009-03-06T21:34:59Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/16777247"},{"isConnection":false,"id":24,"fields":[{"id":47,"type":"yahooid","value":"mona_sunarthi1441","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-05-09T15:33:34Z","created":"2009-02-14T13:59:07Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/24/yahooid/47"},{"id":16777276,"type":"nickname","value":"mona_sunarthi1441","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-05-09T15:33:34Z","created":"2009-05-09T15:33:34Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/24/nickname/16777276"}],"categories":[],"error":0,"restoredId":0,"created":"2009-02-14T13:59:07Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/24"},{"isConnection":false,"id":2,"fields":[{"id":6,"type":"name","value":{"givenName":"Joy","middleName":"","familyName":"Mukherjee","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","flags":[],"categories":[],"updated":"2008-09-22T07:49:00Z","created":"2008-09-15T11:43:12Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/2/name/6"},{"id":7,"type":"email","value":"joy444444@yahoo.com","editedBy":"OWNER","flags":[],"categories":[],"updated":"2008-09-22T07:49:00Z","created":"2008-09-15T11:43:12Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/2/email/7"}],"categories":[],"error":0,"restoredId":0,"created":"2008-09-15T11:43:12Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/2"},{"isConnection":false,"id":26,"fields":[{"id":49,"type":"yahooid","value":"nehahvaidya","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-02-14T14:15:39Z","created":"2009-02-14T14:15:39Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/26/yahooid/49"}],"categories":[],"error":0,"restoredId":0,"created":"2009-02-14T14:15:39Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/26"},{"isConnection":false,"id":16777249,"fields":[{"id":16777275,"type":"yahooid","value":"priya8428","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-04-05T15:08:04Z","created":"2009-04-05T15:08:04Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/16777249/yahooid/16777275"}],"categories":[],"error":0,"restoredId":0,"created":"2009-04-05T15:08:04Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/16777249"},{"isConnection":false,"id":18,"fields":[{"id":42,"type":"nickname","value":"pushf23","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-31T15:27:27Z","created":"2009-01-31T15:27:27Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/18/nickname/42"}],"categories":[],"error":0,"restoredId":0,"created":"2009-01-28T20:19:05Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/18"},{"isConnection":false,"id":7,"fields":[{"id":26,"type":"nickname","value":"redroselove","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-24T14:30:38Z","created":"2009-01-24T14:30:38Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/7/nickname/26"}],"categories":[],"error":0,"restoredId":0,"created":"2009-01-06T16:58:29Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/7"},{"isConnection":false,"id":27,"fields":[{"id":50,"type":"yahooid","value":"roses6_garden","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-02-14T14:17:22Z","created":"2009-02-14T14:17:22Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/27/yahooid/50"}],"categories":[],"error":0,"restoredId":0,"created":"2009-02-14T14:17:22Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/27"},{"isConnection":false,"id":3,"fields":[{"id":8,"type":"name","value":{"givenName":"Alisha","middleName":"","familyName":"Sehgal","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","flags":[],"categories":[],"updated":"2008-09-22T09:44:39Z","created":"2008-09-17T04:07:29Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/3/name/8"},{"id":13,"type":"phone","value":"+919212850293","editedBy":"OWNER","flags":["MOBILE"],"categories":[],"updated":"2008-09-22T09:44:39Z","created":"2008-09-22T09:44:26Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/3/phone/13"},{"id":9,"type":"email","value":"accessalish@yahoo.com","editedBy":"OWNER","flags":[],"categories":[],"updated":"2008-09-22T09:44:39Z","created":"2008-09-17T04:07:29Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/3/email/9"}],"categories":[],"error":0,"restoredId":0,"created":"2008-09-17T04:07:29Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/3"},{"isConnection":false,"id":17,"fields":[{"id":34,"type":"yahooid","value":"sh_saba2007","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-31T15:27:27Z","created":"2009-01-28T20:15:20Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/17/yahooid/34"},{"id":41,"type":"nickname","value":"sh_saba2007","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-31T15:27:27Z","created":"2009-01-31T15:27:27Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/17/nickname/41"}],"categories":[],"error":0,"restoredId":0,"created":"2009-01-28T20:15:20Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/17"},{"isConnection":false,"id":10,"fields":[{"id":22,"type":"name","value":{"givenName":"chetna","middleName":"","familyName":"sharma","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-31T14:38:48Z","created":"2009-01-24T14:13:39Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/10/name/22"},{"id":23,"type":"yahooid","value":"chetnasharma12","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-31T14:38:48Z","created":"2009-01-24T14:13:39Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/10/yahooid/23"}],"categories":[],"error":0,"restoredId":0,"created":"2009-01-24T14:13:39Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/10"},{"isConnection":false,"id":8,"fields":[{"id":25,"type":"nickname","value":"sinhatamanna","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-24T14:30:37Z","created":"2009-01-24T14:30:37Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/8/nickname/25"}],"categories":[],"error":0,"restoredId":0,"created":"2009-01-06T16:58:29Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/8"},{"isConnection":false,"id":9,"fields":[{"id":21,"type":"yahooid","value":"sksheetal","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-24T14:30:37Z","created":"2009-01-06T16:58:29Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/9/yahooid/21"},{"id":24,"type":"nickname","value":"sksheetal","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-24T14:30:37Z","created":"2009-01-24T14:30:37Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/9/nickname/24"}],"categories":[],"error":0,"restoredId":0,"created":"2009-01-06T16:58:29Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/9"},{"isConnection":false,"id":11,"fields":[{"id":27,"type":"yahooid","value":"sparkle_geit","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-26T17:31:56Z","created":"2009-01-25T18:35:30Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/11/yahooid/27"},{"id":28,"type":"nickname","value":"sparkle_geit","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-26T17:31:56Z","created":"2009-01-26T17:31:56Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/11/nickname/28"}],"categories":[],"error":0,"restoredId":0,"created":"2009-01-25T18:35:30Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/11"},{"isConnection":false,"id":4,"fields":[{"id":10,"type":"yahooid","value":"stefhanie_ignacio","editedBy":"OWNER","flags":[],"categories":[],"updated":"2008-11-07T05:43:05Z","created":"2008-09-22T06:15:00Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/4/yahooid/10"},{"id":15,"type":"nickname","value":"stefhanie_ignacio","editedBy":"OWNER","flags":[],"categories":[],"updated":"2008-11-07T05:43:05Z","created":"2008-11-07T05:43:05Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/4/nickname/15"},{"id":11,"type":"phone","value":"9212850293","editedBy":"OWNER","flags":["MOBILE"],"categories":[],"updated":"2008-09-22T07:49:54Z","created":"2008-09-22T07:49:52Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/4/phone/11"}],"categories":[],"error":0,"restoredId":0,"created":"2008-09-22T06:15:00Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/4"},{"isConnection":false,"id":1,"fields":[{"id":1,"type":"name","value":{"givenName":"Gaurav","middleName":"","familyName":"Tyagi","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-17T13:24:31Z","created":"2008-09-09T10:20:30Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/1/name/1"},{"id":4,"type":"yahooid","value":"tyagii_gaurav_1985","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-17T13:24:31Z","created":"2008-09-09T10:20:30Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/1/yahooid/4"},{"id":3,"type":"phone","value":"9718473635","editedBy":"OWNER","flags":["MOBILE"],"categories":[],"updated":"2009-01-17T13:24:31Z","created":"2008-09-09T10:20:30Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/1/phone/3"},{"id":2,"type":"email","value":"tyagii_gaurav_1985@yahoo.co.in","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-17T13:24:31Z","created":"2008-09-09T10:20:30Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/1/email/2"}],"categories":[],"error":0,"restoredId":0,"created":"2008-09-09T10:20:30Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/1"},{"isConnection":false,"id":15,"fields":[{"id":32,"type":"yahooid","value":"zeeba_khann","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-31T15:27:28Z","created":"2009-01-28T20:12:09Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/15/yahooid/32"},{"id":43,"type":"nickname","value":"zeeba_khann","editedBy":"OWNER","flags":[],"categories":[],"updated":"2009-01-31T15:27:28Z","created":"2009-01-31T15:27:28Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/15/nickname/43"},{"id":39,"type":"phone","value":"9212850293","editedBy":"OWNER","flags":["MOBILE"],"categories":[],"updated":"2009-01-28T20:29:57Z","created":"2009-01-28T20:29:55Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/15/phone/39"}],"categories":[],"error":0,"restoredId":0,"created":"2009-01-28T20:12:09Z","updated":"2014-11-11T07:35:06Z","uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contact/15"}],"count":23,"start":0,"total":23,"uri":"http://social.yahooapis.com/v1/user/BYY5K3R37KL4IWYRFSTYUJWDT4/contacts","cache":true}}

您的数据结构和 json 格式不匹配。

使用以下数据结构解析json。

public class Field
{
    public int id { get; set; }
    public string type { get; set; }
    public object value { get; set; }
    public string editedBy { get; set; }
    public List<object> flags { get; set; }
    public List<object> categories { get; set; }
    public string updated { get; set; }
    public string created { get; set; }
    public string uri { get; set; }
    public bool? isConnection { get; set; }
}

public class Contact
{
    public bool isConnection { get; set; }
    public int id { get; set; }
    public List<Field> fields { get; set; }
    public List<object> categories { get; set; }
    public int error { get; set; }
    public int restoredId { get; set; }
    public string created { get; set; }
    public string updated { get; set; }
    public string uri { get; set; }
}

public class Contacts
{
    public List<Contact> contact { get; set; }
    public int count { get; set; }
    public int start { get; set; }
    public int total { get; set; }
    public string uri { get; set; }
    public bool cache { get; set; }
}

public class RootObject
{
    public Contacts contacts { get; set; }
}

每当您对正确的数据结构感到困惑时,请使用 json to c# converter

借助 Whosebug 的一位编码人员提供的 json 到 C# 转换器 class link,我能够检测到 class 中的主要问题。问题是我必须将我的 YContacts class 的 public 变量作为列表类型,所以唯一的更新是 -

public class YContacts
{
    public List<YContact> contact { get; set; }
}

现在它运行良好。 谢谢和问候。

变化自

public YContact contact { get; set; }

public List<YContact> contact { get; set; }

这是完整的例子 Go to example