Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在newtonsoft中反序列化JSON时忽略空值_C#_Json_Json.net - Fatal编程技术网

C# 在newtonsoft中反序列化JSON时忽略空值

C# 在newtonsoft中反序列化JSON时忽略空值,c#,json,json.net,C#,Json,Json.net,我有以下来自服务器的json { "contactList":[{ "contactName":"Jhon", "address":null, "phone":null, "contactId":99932 }] } Response responseData = await Task.Run(() => JsonConvert.DeserializeObject<Response>(content, jsonSet

我有以下来自服务器的json

{
 "contactList":[{

      "contactName":"Jhon",
      "address":null,
      "phone":null,
      "contactId":99932

}]

}
  Response responseData = await Task.Run(() => JsonConvert.DeserializeObject<Response>(content, jsonSettings));
现在,当我使用
JsonConvert.DeserializeObject(content)
反序列化时,我需要以下输出

{
     "contactList":[{

          "contactName":"Jhon",
          "contactId":99932

    }]

    }
我尝试了以下代码,但它不工作

 JsonSerializerSettings jsonSettings = new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore,
                        MissingMemberHandling = MissingMemberHandling.Ignore
                    };
这是我的联系方式

public class Contact 
    {
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public String address { set; get; }

       [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
         public String phone { set; get; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
         public String name { set; get; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
         public String id { set; get; }
  }
反应模型

     [JsonObject(MemberSerialization = MemberSerialization.OptIn)]
 public class Response 
    {
         [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public IList<SignodeMSA.Model.Master.Contact> contactsList { get; }
  }
[JsonObject(MemberSerialization=MemberSerialization.OptIn)]
公众课堂反应
{
[JsonProperty(NullValueHandling=NullValueHandling.Ignore)]
公共IList联系人列表{get;}
}
在从服务器获取它之后,我正在进行反序列化

{
 "contactList":[{

      "contactName":"Jhon",
      "address":null,
      "phone":null,
      "contactId":99932

}]

}
  Response responseData = await Task.Run(() => JsonConvert.DeserializeObject<Response>(content, jsonSettings));
Response responseData=wait Task.Run(()=>jsoninvert.DeserializeObject(content,jsonSettings));

我认为您需要手动从json字符串中删除该属性


可能是这样的:

json设置必须工作,您如何使用它们?在序列化数据的地方张贴代码。@SiyavashHamdi Json.net能够在被告知时不写出空值。jsonSettings是正确的,可能没有使用它。已将您正在反序列化的问题更新为静态类型的
联系人
,该联系人的属性
电话
id
都是.NET类的一部分。他们不能消失<代码>NullValueHandling。忽略仅影响序列化。