你可以使用字符串数组转换为字符串作为取代后,
JSONArray jsonArray = new JSONArray();
jsonArray.put(1);
jsonArray.put("empty");
jsonArray.put(2);
jsonArray.put(3);
jsonArray.put("empty");
jsonArray.put(4);
jsonArray.put("empty");
System.err.println(jsonArray);
String jsonString = jsonArray.toString();
String replacedString = jsonString.replaceAll("\"empty\",", "").replaceAll("\"empty\"", "");
jsonArray = new JSONArray(replacedString);
System.out.println(jsonArray);
之前更换:
jsonArray is [1,"empty",2,3,"empty",4,"empty"]
替换后:
jsonArray is [1,2,3,4]
来源
2013-12-19 13:08:10
AJJ
JSONArray从哪个API中使用? –
iam使用此导入org.json.JSONArray; – user3112115
已经有链接解决方案http://stackoverflow.com/questions/18497162/how-to-remove-element-from-json-array –