1

i need to convert my ArrayList<Map<String, String>> object to the JSONArray

ArrayList<Map<String, String>> dataList = new ArrayList<Map<String, String>>();
//I tried this

JSONArray jsonArray = new JSONArray(dataList);  

// I am importing (java-json.jar) for converting ArrayList to JSONArray
// But i can't put this array in to JqGrid in my jsp page it's does not give me any output
1
  • show your jsp source code Commented Mar 14, 2014 at 7:08

1 Answer 1

2

You can try Google's Gson library for easy conversion of Java objects to Json and vice versa

Try below code

Gson gson = new Gson();
JsonArray jsonArray = gson.toJsonTree(dataList).getAsJsonArray();

EDIT : Convert jsonArray to string

String jsonStr = gson.toJson(jsonArray); //This will convert JsonArray to Java string
Sign up to request clarification or add additional context in comments.

2 Comments

i will try you code if know how to convert that data into Json String then please tell me.
Uttam Thanks for the giving me response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.