如何在C#中序列化JSON?

如何在C#中序列化JSON?,c#,json,serialization,C#,Json,Serialization,无法在C中序列化json# 我的C语言代码是- 您的数据结构和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

无法在C中序列化json#

我的C语言代码是-


您的数据结构和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; }
}
公共类字段
{
公共int id{get;set;}
公共字符串类型{get;set;}
公共对象值{get;set;}
由{get;set;}编辑的公共字符串
公共列表标志{get;set;}
公共列表类别{get;set;}
公共字符串已更新{get;set;}
已创建公共字符串{get;set;}
公共字符串uri{get;set;}
公共布尔?断开连接{get;set;}
}
公共类联系人
{
公共布尔值断开连接{get;set;}
公共int id{get;set;}
公共列表字段{get;set;}
公共列表类别{get;set;}
公共整数错误{get;set;}
公共int restoredId{get;set;}
已创建公共字符串{get;set;}
公共字符串已更新{get;set;}
公共字符串uri{get;set;}
}
公共类联系人
{
公共列表联系人{get;set;}
公共整数计数{get;set;}
public int start{get;set;}
公共整数总计{get;set;}
公共字符串uri{get;set;}
公共布尔缓存{get;set;}
}
公共类根对象
{
公共联系人联系人{get;set;}
}
每当您对正确的数据结构感到困惑时,请使用由stackoverflow的一位同事提供的json到C#converter类链接,我能够检测到我的类中的主要问题。问题是我必须将YContacts类的to public变量设置为列表类型,因此唯一的更新是-

public class YContacts
{
    public List<YContact> contact { get; set; }
}
公共类YContacts
{
公共列表联系人{get;set;}
}
现在它工作得非常好。 谢谢和问候。

public YContact contact { get; set; }

公共列表联系人{get;set;}
这里是完整的例子

课堂上有什么问题吗?你能详细告诉我吗?你厌倦谷歌搜索了吗。。?网络上有很多例子,这里是一个转换器非常好的例子。所以作品喜欢魅力。我已经用了很长时间了。没有任何问题。
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; }
}
public class YContacts
{
    public List<YContact> contact { get; set; }
}
public YContact contact { get; set; }
public List<YContact> contact { get; set; }