Pawan
Pawan

Reputation: 32331

Converting java String to json object

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

Answers (3)

ShyJ
ShyJ

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

Dan D.
Dan D.

Reputation: 32391

Use the json.org library. It is as simple as new JSONObject(s); where s is a String.

Upvotes: 2

Related Questions