-1

I have the following string and I need to split it to get the two objects inside:

[Object{value1="1", value2="2"}, Object{Value1="1", value2="2"}]
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
user3478224
  • 73
  • 1
  • 2
  • 11

1 Answers1

-1

You could try:

String[] splitTextObject = YOUR_STRING.split(", ");
String object1 = splitTextObject[0];
String object2 = splitTextObject[1];
...

But I don't think you actually need to split the string this way in order to achieve getting each object, and instead you should consider parsing your JSON. Perhaps utilise GSON.

  • 1
    I appreciate your help, your solution only splits until Object{value1="1" – user3478224 Dec 20 '16 at 15:29
  • Yes, your original question didn't include spaces between each value. You could instead try String[] splitTextObject = YOUR_STRING.split("Object"); But this will achieve less than desirable results. You are best off looking into parsing JSON. – JamesSwinton Dec 20 '16 at 15:33
  • Ok, let me try a more advance solution. I used GsonUtil.getGson().fromJson(string, Formatter.class) but I get a JsonSyntaxException expected GSON Object, found GSON Array – user3478224 Dec 20 '16 at 15:42
  • JsonSyntaxException expected BEGIN_OBJECT but was _BEGIN_ARRAY – user3478224 Dec 20 '16 at 15:45
  • I can't help you from the comments of my original answer. You should consider asking a new question altogether, focused on your GSON/JSON queries – JamesSwinton Dec 20 '16 at 15:47
  • Done, http://stackoverflow.com/questions/41249123/convert-json-response-into-listt – user3478224 Dec 20 '16 at 18:39
  • The question doesn't have JSON anyway. And, by the way Gson is not an acronym like JSON, so it is not all caps. – OneCricketeer Dec 20 '16 at 18:55