Reputation: 995
I have the following string
["[email protected]","[email protected]"]
I am using String.split(",")
to get String[]. But array contents consist of '[' and '"'.
I need to get the actual strings with out quotes. Is there a library or method with which I can do it?
At present I am doing like this.
recipients = recipients.replace("\"", "");
recipients = recipients.replace("[", "");
recipients = recipients.replace("]", "");
String[] totalRecipients = recipients.split(",");
Upvotes: 0
Views: 1754
Reputation: 41220
De-serialize the json string to java object using boon
or jackson
3rd party library.
Boon Example -
ObjectMapper mapper = JsonFactory.create();
String[] recipientArray = mapper.readValue(recipients , String[].class, String.class);
Find Java Boon vs jackson json - Benchmarks - here
Source : Link
Upvotes: 4
Reputation: 1588
you can use of google's gson and to decode your json to String[]
you can simply use this line of code
Gson gson = new Gson();
String[] myArray = gson.fromJson(yourjson,String[].class);
Upvotes: 1
Reputation: 781
I suggest you to use json library to solve it.
String s = "[\"[email protected]\",\"[email protected]\"]";
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readValue(s);
for(JsonNode n : node){
.......
}
Upvotes: 1