Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

This question already has an answer here:

This is the result of my servlet in json Array that is converted to string using

 /*Converting Json Array to String*/
         StringWriter toStringF = new StringWriter();
         arrayFood.writeJSONString(toStringF);
         /*Printing Json Array - String*/
         response.getWriter().println(toStringF.toString());

The result shows

[{"Food":{"foodName":"Chicken Tenders","foodDescription":"Deep fried chicken tenders with rice","price":150.0,"foodID":59,"rating":5.0}},{"Food":{"foodName":"Roasted Duck\/Asado Rice","foodDescription":"Roasted duck with asado rice","price":210.0,"foodID":32,"rating":4.0}},{"Food":{"foodName":"Steamed Minced Beef Rice","foodDescription":"Steamed minced beef with rice","price":140.0,"foodID":40,"rating":4.0}},{"Food":{"foodName":"Buffalo Wings","foodDescription":"Deep fried chicken wings coated in hot sauce","price":160.0,"foodID":54,"rating":4.0}},{"Food":{"foodName":"H Burger","foodDescription":"The Hatchery's specialty burger","price":135.0,"foodID":58,"rating":4.0}}] 

I tried to search the net on how to convert the jsonArrayStrings to arraylist of object but there are different kinds of codes and imports and right now I am totally confused which to use. It will help me a lot if there is a simpler way to do this.

I want to convert the above JsonArray Strings to an object.. something like the FoodName can be set into its properties like this one ex. food.FoodName(jsonObject.getString("FoodName"))..

ArrayList<Food> food = new ArrayList<Food>();
share|improve this question

marked as duplicate by BalusC java Dec 4 '15 at 7:57

This question was marked as an exact duplicate of an existing question.

    
Try Jackson mapper github.com/FasterXML/jackson-databind – Aakash Dec 4 '15 at 7:56

Refer this site

JSONArray arr = new JSONArray(yourJSONresponse);
List<String> list = new ArrayList<String>();
for(int i = 0; i < arr.length(); i++){
    list.add(arr.getJSONObject(i).getString("name"));
}
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.