Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONObject to String Android

Tags:

java

json

android

how can I convert a JSONObject like "{hello1: hi, hello2: hey}" to "hello1: hi, hello2: hey" without these brackets { } ?

I know that there is a opportunity to use JSONObject.tostring but then I'll get a string with the brackets.

Thanks all.

like image 646
tsync Avatar asked May 09 '11 07:05

tsync


1 Answers

Just do a substring or string replace.

Pseudo substring Example:

JSONObject a  = new JSONObject("{hello1: hi, hello2: hey}");
String b = a.toString().substring(1, a.toString().length() - 1);

Pseudo string replace Example:

JSONObject a  = new JSONObject("{hello1: hi, hello2: hey}");
String b = a.toString().replace("{", "");
String c = b.toString().replace("}", "");
like image 170
Mark Mooibroek Avatar answered Oct 04 '22 02:10

Mark Mooibroek