List and JSONArray convert each other
List to JSONArray
After copying, run it directly, the code is as follows:
("List to JSONArray"); List<String> list = new ArrayList<>(); ("a"); ("b"); ("c"); ("\nOriginal list: " + list); // Method 1: Use JSONArray to construct the method JSONArray jsonArray1 = new JSONArray((list)); ("Method 1:" + jsonArray1); // Method 2: Convert List to JSON string, both are OK JSONArray jsonArray2 = ((list)); //JSONArray jsonArray2 = ((list)); ("Method 2:" + jsonArray2); // Method 3: Convert List to JSON string and then force it to JSONArray jsonArray3 = (JSONArray) (list); ("Method 3:" + jsonArray3);
JSONArray to List
("JSONArray to List"); JSONArray array = new JSONArray(); ("a"); ("b"); ("c"); ("\nOriginal JSONArray: " + array); // Both are available List<String> strList = ((), ); // List<String> strList = ((), ); (": " + strList);
Summarize
This is the article about the conversion of JSONArray of List and fastjson in Java. This is all about this. For more information about the conversion of JSONArray of List and fastjson in Java, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!