2012-11-21 165 views
0

我有这种格式转换Java字符串以JSON对象

"{name:MyName, rage:200, height:100}" 

Java字符串,我需要将其转换为JSONObject的应该是以下格式

{name:MyName, rage:200, height:100} // that is i want to remove the start and end double quotes fro the above string . 

有人能帮助我在这。

回答

2

使用json.org库。它与new JSONObject(s);一样简单,其中s是String

0

如果你只是想删除引号,使用StringUtils.mid应该做你的工作

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