Sashi Kant
Sashi Kant

Reputation: 13465

Parsing a JSON Object in Java having special characters

I am stuck in a situation, where my JSONString (ruleFormJSONString) looks like :

{
"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"
}

As you can see there are 2 attributes named fromTime and toTime which has a :

So while parsing this in Java, I used

JSONObject  ruleFormJSON    =   JSONObject.fromString(ruleFormJSONString);
String      fromTime        =   (String)ruleFormJSON.getString("fromTime");
String      toTime          =   (String)ruleFormJSON.getString("toTime");

I am getting a NumberFormatException which is

java.lang.NumberFormatException: For input string: "18:00"

So please suggest me how, to get the value in the corresponding String variable.

Any help will be appreciated.

Upvotes: 0

Views: 2043

Answers (1)

freedev
freedev

Reputation: 30067

It seems there is an error on this line:

"listOfBusinessdays":"1","2","5","6","7"],

A closed bracket square but no open bracket before. May be this hang up the parser.

Upvotes: 1

Related Questions