程序代码如下
public class tetet {
public static void main(String[] args) throws JSONException {
//第一种方式
String json = "[\"1\", \"2\"]";
("去除之前字符串:" + json);
String t = ("\\\"","");
("去除双引号和斜杠后:"+t);
String replaceAll = ("[", "").replace("]","");
("去除左右中括号后:"+replaceAll);
String [] id = (",");
List<String> ll = new ArrayList<>();
for(String s:id){
s = "\"" + s + "\"";
(s);
}
("还原字符串:" + ());
//第二种方式
String text = "[\"3\", \"4\"]";
JSONArray jsonArray = (text);
StringJoiner stringJoiner = new StringJoiner(",");
for (int i=0;i<();i++){
((i))
}
("JSONArray方式:"+());
}
}
输出结果如下:
去除之前字符串:["1", "2"]
去除双引号和斜杠后:[1, 2]
去除左右中括号后:1, 2
还原字符串:["1", " 2"]
JSONArray方式:3,4,5