我只是在尝试为我的单元测试构建一个json字符串,并且意外地,以下代码返回系统格式异常。错误消息表明它正在尝试解析日期,这对我来说很奇怪。我不是要解析日期。
class Program
{
static void Main(string[] args)
{
Console.WriteLine(GetJson());
Console.ReadKey();
}
static string GetJson(string dateStr = "", string lta = "5.25")
{
return String.Format("[{\"dateBooking\":\"{0}\",\"lta\":\"{1}\"}]", dateStr, lta);
}
}
Run Code Online (Sandbox Code Playgroud)
可以很容易地复制它,但是我要添加异常详细信息:
“ mscorlib.dll中发生了类型为'System.FormatException'的未处理的异常
其他信息:输入字符串的格式不正确。”