Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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# 列表<;类>;。选择抛出System.FormatException异常_C#_Asp.net - Fatal编程技术网

C# 列表<;类>;。选择抛出System.FormatException异常

C# 列表<;类>;。选择抛出System.FormatException异常,c#,asp.net,C#,Asp.net,代码抛出(System.FormatException:输入字符串的格式不正确。)Exception,出现了什么问题? 设计师类 public class designer { public string name { get; set; } public string category { get; set; } } getData.aspx页面 List<designer> lst = DataAccess.GetDesigners(); return Str

代码抛出(System.FormatException:输入字符串的格式不正确。)Exception,出现了什么问题?

设计师类

public class designer
{
    public string name { get; set; }
    public string category { get; set; }
}
getData.aspx页面

List<designer> lst = DataAccess.GetDesigners();
return String.Join(",", lst.Select(x => String.Format("{ label: \"{0}\", category: \"{1}\" }", x.name, x.category)));
看起来像

var lst = DataAccess.GetDesigners().Where(x => x != null);

保护您不受此异常的影响

您的代码的问题是您正在使用格式字符串中的
{
,因此要转义
{
,它应该后跟
{
}
应该后跟
}

lst.Select(x => String.Format("{{ label: \"{0}\", category: \"{1}\" }}", x.name, x.category));

记住:括号
{}
应该在使用
字符串时转义。Format

数据访问。GetDesigners
返回
null
?我添加了异常详细信息+1。我不知道你可以这样转义括号。文档中根本没有提到它。谢谢!
lst.Select(x => String.Format("{{ label: \"{0}\", category: \"{1}\" }}", x.name, x.category));