Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.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#删除json中的NULL?_C#_Asp.net_Json_Null - Fatal编程技术网

如何使用c#删除json中的NULL?

如何使用c#删除json中的NULL?,c#,asp.net,json,null,C#,Asp.net,Json,Null,我在json中得到空值。我正在使用JavaScriptSerializer转换为json。请任何人帮我解决我的问题。提前谢谢 Json: 类别: public class Bordingpoints { public string location { get; set; } public int id { get; set; } public string time { get; set; }

我在json中得到空值。我正在使用JavaScriptSerializer转换为json。请任何人帮我解决我的问题。提前谢谢

Json:

类别:

 public class Bordingpoints
        {
            public string location { get; set; }
            public int id { get; set; }
            public string time { get; set; }

        }
反序列化:

 var bp = new Bordingpoints[array1.Count];
                    for (int i = 0; i < array1.Count; i++)
                    {
                        try
                        {
                            JArray pickups = (JArray)array1[i]["boardingPoints"];
                            for (int j = 0; j < pickups.Count; j++)
                            {
                                string location = (string)pickups[j]["location"];
                                int id = (int)pickups[j]["id"];
                                string time = (string)pickups[j]["time"];

                                if (!bpid.Contains(id))
                                {
                                    bp[i] = new Bordingpoints();
                                    bp[i].location = location;
                                    bp[i].id = id;
                                    bp[i].time = time;
                                    bpid.Add(id);

                                }
                            }
                        }


JavaScriptSerializer js = new JavaScriptSerializer();

                    string bdpt = js.Serialize(bp);
var bp=新的边界点[array1.Count];
for(int i=0;i

基于某些条件,我跳过了一些对象,当时我得到了空值。请帮助我。

数组中有空项。您可以尝试以下方法。可能有更好的方法,但这应该可以解决问题

替换

string bdpt = js.Serialize(bp);


您需要包含用于进行实际反序列化的代码。可能重复的@npinti请查看代码
string bdpt = js.Serialize(bp);
string bdpt = js.Serialize(bp.Where(p=>p!=null));