千巷猫影
我遇到了这个确切的异常,只是它与解析数字输入无关。所以这不是OP问题的答案,但我认为分享知识是可以接受的。我声明了一个字符串,并将其格式化,以便与JQTree它需要花括号({})。您必须使用双大括号才能将其接受为格式正确的字符串:string measurements = string.empty;measurements += string.Format(@"
{{label: 'Measurement Name: {0}',
children: [
{{label: 'Measured Value: {1}'}},
{{label: 'Min: {2}'}},
{{label: 'Max: {3}'}},
{{label: 'Measured String: {4}'}},
{{label: 'Expected String: {5}'}},
]
}},",
drv["MeasurementName"] == null ? "NULL" : drv["MeasurementName"],
drv["MeasuredValue"] == null ? "NULL" : drv["MeasuredValue"],
drv["Min"] == null ? "NULL" : drv["Min"],
drv["Max"] == null ? "NULL" : drv["Max"],
drv["MeasuredString"] == null ? "NULL" : drv["MeasuredString"],
drv["ExpectedString"] == null ? "NULL" : drv["ExpectedString"]);希望这将有助于发现这个问题但不解析数值数据的其他人。
胡说叔叔
问题有一些可能发生错误的情况:因为textBox1.Text只包含数字,但数字是太大/太小因为textBox1.Text包含:(A)非数字(除外)space在开始/结束时,-(一开始)和/或(B)您的代码的应用区域性中有1000个分隔符,而没有指定NumberStyles.AllowThousands或者您指定NumberStyles.AllowThousands但错了thousand separator在文化和/或(C)十进制分隔符(不应存在于int分析)不确定的例子:案例1a = Int32.Parse("5000000000"); //5 billions, too largeb = Int32.Parse("-5000000000"); //-5 billions, too small//The limit for int (32-bit integer) is only from -2,147,483,648 to 2,147,483,647案例2 a)a = Int32.Parse("a189"); //having a a = Int32.Parse("1-89"); //having - but not in the beginninga = Int32.Parse("18 9"); //having space, but not in the beginning or end案件2 b)NumberStyles styles = NumberStyles.AllowThousands;a = Int32.Parse("1,189"); //not OK, no NumberStyles.AllowThousandsb = Int32.Parse("1,189", styles, new CultureInfo("fr-FR")); //not OK, having NumberStyles.AllowThousands but the culture specified use different thousand separator案件2 c)NumberStyles styles = NumberStyles.AllowDecimalPoint;a = Int32.Parse("1.189", styles); //wrong, int parse cannot parse decimal point at all!似乎不确定,但实际上是好的例子:案例2 a)OKa = Int32.Parse("-189"); //having - but in the beginningb = Int32.Parse(" 189 "); //having space, but in the beginning or end案例2 b)OKNumberStyles styles = NumberStyles.AllowThousands;a = Int32.Parse("1,189", styles); //ok, having NumberStyles.AllowThousands in the correct cultureb = Int32.Parse("1 189", styles, new CultureInfo("fr-FR")); //ok, having NumberStyles.AllowThousands and correct thousand separator is used for "fr-FR" culture解在所有情况下,请检查textBox1.Text使用VisualStudio调试器,并确保它具有完全可以接受的数字格式。int范围。就像这样:1234此外,你也可以考虑使用TryParse而不是Parse若要确保非解析数字不会导致异常问题,请执行以下操作。检查…的结果TryParse如果不处理的话trueint val;bool result = int.TryParse(textbox1.Text, out val);if (!result)
return; //something has gone wrong//OK, continue using val