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.
Dante May Code
11.3k9 gold badges52 silver badges83 bronze badges
asked Nov 21, 2012 at 15:54
Pawan
32.5k110 gold badges270 silver badges447 bronze badges
3 Answers 3
Use the json.org library. It is as simple as new JSONObject(s); where s is a String.
answered Nov 21, 2012 at 15:58
Dan D.
32.4k6 gold badges66 silver badges81 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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.
answered Nov 21, 2012 at 16:00
David
2,7222 gold badges21 silver badges32 bronze badges
Comments
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
answered Nov 21, 2012 at 16:35
ShyJ
4,6801 gold badge22 silver badges19 bronze badges
Comments
lang-java