我陷入了我的JSONString
(ruleFormJSONString)看起来像这样的情况:
{
"ruleDescription":"Test Rule2 Description",
"urlId":"1",
"listOfBusinessdays":["1","2","5","6","7"],
"status":"1",
"hierarchyId":"3",
"fromTime":"08:00",
"toTime":"18:00",
"dcnid":"1",
"eventId":"1",
"rowstate":"1",
"listOfLocations":["ASM","DEL"],
"ruleName":"Test Rule2",
"ruleId":"7","msgId":"1"
}
如您所见,有两个名为
fromTime
和toTime
的属性,其中有一个:
所以在用Java解析时
JSONObject ruleFormJSON = JSONObject.fromString(ruleFormJSONString);
String fromTime = (String)ruleFormJSON.getString("fromTime");
String toTime = (String)ruleFormJSON.getString("toTime");
我得到一个
NumberFormatException
java.lang.NumberFormatException:对于输入字符串:“ 18:00”
因此,请建议我如何获取对应的
String
变量中的值。任何帮助将不胜感激。
最佳答案
似乎这条线上有错误:
"listOfBusinessdays":"1","2","5","6","7"],
一个方括号是封闭的,但之前没有方括号。
可能是这挂断了解析器。