this is the JSONArray: String json = [{"1":"Kenny", "2":"Tom", "3":"Mosoti"}]; now i want to get a string array of values only eg Kenny, Tom, Mosoti
2 Answers
You may use any json parser to do that for instance Jackson.
It is not a good option to write your own parser as it is error-prone. Also don't re-invent the wheel.
3 Comments
user1759570
am using this package org.json.*
user1759570
help me out using the package
Ivaylo Strandjev
@user1759570 have a look here
Yeah, you should go with a mainstream library/framework like Jackson, you can read more about it here: http://wiki.fasterxml.com/JacksonInFiveMinutes
A basic example would be something like:
private static MailData unMarshallJson(String literalJson) throws JAXBException, IOException {
Data data = null;
ObjectMapper mapper = new ObjectMapper();
data = mapper.readValue(literalJson, Data.class);
return data;
}
Where the Data class is a class corresponding to the parsed data, read the link that I provided for more info.