string.Format出现异常:输入字符串的格式不正确 Exception during StringFormat

时间:2023-03-08 16:45:16

错误信息:Exception during StringFormat:输入字符串的格式不正确

“System.FormatException”类型的未经处理的异常在 mscorlib.dll 中发生

其他信息: 输入字符串的格式不正确。

string s = string.Format("{return:\"{0}\"}", result);//这里报错  

后来发现是 占位符 result 里含有 "{}" 大括号导致。

解决办法:替换处理result,

用两个 { 或者 }连写表示单个。

或者其他办法