0

Doing some Java these times. I have a String like this :

String output = [{"id":1,"enterpriseId":1,"firstName":"Arnaud","lastName":"Arnaud","sessionId":"2_MX4"},
                 {"id":3,"enterpriseId":5,"firstName":"Benjamin","lastName":"Benjamin","sessionId":"1_MX40"},
                 {"id":4,"enterpriseId":1,"firstName":"Nicolas","lastName":"Nicolas","sessionId":"1_MX40N"},
                 {"id":5,"enterpriseId":1,"firstName":"Eliott","lastName":"Eliott","sessionId":"1_MX40NT"}]

As you can see, it contains som JSON formated text. What I want is transform this String into an array of String's, in order to parse each row of the array to a JSONObject. Tried some basic things as :

String[] strArray = new String[] {output};

But this doesn't work.. Any ideas ? Thanks !

Eliott
  • 840
  • 8
  • 10
  • why parse each entry separately? why not just parse the whole thing as a json array? – jonk Jun 01 '16 at 15:03
  • @jonk well a JSONObject shouldn't start by "[", that's why I want a String's array first. Plus I want as much JSONObjects as objects in the output String – Eliott Jun 01 '16 at 15:07
  • I don't know what you meant by the second sentence, but I meant parse the whole thing as a `JSONArray` then you can loop through and grab each `JSONObject` from it, with which you can then do whatever you want (assuming you're using `org.json` or similar, can obv. parse it with another lib). Anyway the linked question should provide the answers you need. – jonk Jun 01 '16 at 16:00

0 Answers0