String str = "[[28.667949,77.287067,232,0,0.8,5],[28.667949,77.287067,232,0,0.8,5]]";
我有一个String,并且想要将其转换为Array,List或Object中除String之外的任何类型。
预期输出:
List/Array/Object =
[[28.667949,77.287067,232,0,0.8,5],[28.667949,77.287067,232,0,0.8,5]]
答案 0 :(得分:1)
如果数据组很重要,这是一种算法:
1. create new List<List<String>> strList
2. String [] strs= str.split("],")
3. loop each str in strs
3.1 replace all existence of "[" and "]" of str
3.2 strList.add(Arrays.asList(str.split(",")))
希望这会有所帮助!
答案 1 :(得分:0)
你必须做
List ls = Arrays.asList(str.replaceAll("\\[", "").replaceAll("\\]", "").split(","));
答案 2 :(得分:0)
可以解决此问题
1。)首先用“”替换所有的[[和']'
str = str.replaceAll("[","");
str = str.replaceAll("]","");
2。)然后,您可以使用“,”分割字符串。
which gives u an array.
String[] split = str.split(",");