Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/341.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# 处理列表c中字符串和double的空值#_C#_Asp.net_String_List_.net Core - Fatal编程技术网

C# 处理列表c中字符串和double的空值#

C# 处理列表c中字符串和double的空值#,c#,asp.net,string,list,.net-core,C#,Asp.net,String,List,.net Core,如何在c#中处理字符串和双精度的空值? 我在列表中得到的值是反序列化后的数据 string datareq = rqbody["Response"]; List<GoogleProductDetails> data = JsonConvert.DeserializeObject<List<GoogleProductDetails>>(datareq); 等等 如果有空值,它会处理空值吗 public class GoogleProduc

如何在c#中处理字符串和双精度的空值? 我在列表中得到的值是反序列化后的数据

string datareq = rqbody["Response"];

List<GoogleProductDetails> data = JsonConvert.DeserializeObject<List<GoogleProductDetails>>(datareq);
等等

如果有空值,它会处理空值吗

public class GoogleProductDetails{
 
    public string id { get; set; }
    public string name { get; set; }
    public string description { get; set; }
    public string brand { get; set; }
    public string ean { get; set; }
    public string mediaStorageKey { get; set;}
    public int? maxQuantity { get; set; }
    public double? price { get; set; }
    public double? size { get; set; }
    public string sizeUnits { get; set; }

}

也许可以让你的属性为空?但是,您也可以在属性上方添加以下属性:
[JsonProperty(NullValueHandling=NullValueHandling.Ignore)]
您能给string举个例子吗?可能类似于
product.ShippingWeight.Unit=string.IsNullOrEmpty(数据[0].sizeUnits)?string.Empty:数据[0].sizeUnits.ToString()可能它在这里失败了
Convert.ToString(数据[0].sizeUnits)
,因为您试图将
null
强制转换为字符串;不要这样做。double也可以吗?你必须显示类
GoogleProductDetails
。什么类型是
sizeUnits
size
public class GoogleProductDetails{
 
    public string id { get; set; }
    public string name { get; set; }
    public string description { get; set; }
    public string brand { get; set; }
    public string ean { get; set; }
    public string mediaStorageKey { get; set;}
    public int? maxQuantity { get; set; }
    public double? price { get; set; }
    public double? size { get; set; }
    public string sizeUnits { get; set; }

}