使用Gson库将ArrayList转换为JsonArray. Gson gson = new GsonBuilder().create(); JsonArray myCustomArray = gson.toJsonTree(myCustomList).getAsJsonArray(); Run Code Online (Sandbox Code Playgroud) 这不是OP想要的org.json.JSON
ArrayList<String>listdata=newArrayList<String>();JSONArray jArray=(JSONArray)jsonObject;if(jArray!=...
当您在第一个performFiltering(CharSequence constraint)中返回JSONArray对象而不是ArrayList时,if statement...
您可以使用 ObjectMapper 接收 JSON 字符串,然后将字符串转换为 JSONArray。 import com.fasterxml.jackson.databind.ObjectMapper; import org.json.JSONArray; List<CustomObject> myList = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writeValueAsString(myList); J...
您可以只创建一个JSONObject,而不是将JSON字符串转换为ArrayList甚至是Map 。此对象可以根据需要按键获取字符串值,也可以删除对象。 要从JSONObject格式正确的JSON字符串创建一个,只需调用相应的构造函数即可。 JSONObject json = new JSONObject(jsonString); 反对 回复 2019-08-19 3...