I need to convert String in Json format to a List object and I am using below program to do it.
public class JsonStringToListConversion {
public static void main(String[] args) {
String userProfile = "{\"name\":\"Arun\", Skills:[\"Java\",\"Spring\",\"hibernate\"]}";
JSONObject userProfileJO = (JSONObject)JSONSerializer.toJSON(userProfile);
List<String> skills = new ArrayList<String>();
skills = (List<String>)userProfileJO.getJSONArray("Skills");
System.out.println(skills);
}
}
I am using Java 1.6 and JSON-lib 2.4
Please help me to know whether this is the correct way to do this?
Particularly I am typecasting JSONArray to List and it is working whether it is correct?