Reputation: 32331
I have a java String in this format
"{name:MyName, rage:200, height:100}"
and i need to convert it to JsonObject which should be in below format
{name:MyName, rage:200, height:100} // that is i want to remove the start and end double quotes fro the above string .
Can some one help me in this.
Upvotes: 0
Views: 3988
Reputation: 4650
If you just want to remove the quotes, using StringUtils.mid should do your job
final String input = "\"{name:MyName, rage:200, height:100}\"";
final String result = StringUtils.mid (input, 1, input.length () - 2);
// result should not contain the beginning and ending quotes
Upvotes: 0
Reputation: 2702
Have you tried the Jackson JSON libraries? It's pretty easy to use an ObjectMapper to create a JsonNode as a tree structure and parse away from there.
Upvotes: 1
Reputation: 32391
Use the json.org library. It is as simple as new JSONObject(s);
where s is a String
.
Upvotes: 2