String str = "[[28.667949,77.287067,232,0,0.8,5],[28.667949,77.287067,232,0,0.8,5]]";我有一個(gè)字符串,想將它轉(zhuǎn)換成除字符串以外的數(shù)組、列表或?qū)ο笾械娜魏晤愋?。預(yù)期輸出: List/Array/Object =
[[28.667949,77.287067,232,0,0.8,5],[28.667949,77.287067,232,0,0.8,5]]
3 回答

Qyouu
TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊
你必須做
List ls = Arrays.asList(str.replaceAll("\\[", "").replaceAll("\\]", "").split(","));

瀟瀟雨雨
TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊
有解決辦法
1.)首先用“”替換所有'['和']'
str = str.replaceAll("[",""); str = str.replaceAll("]","");
2.)然后你可以用“,”分割字符串
which gives u an array. String[] split = str.split(",");

哆啦的時(shí)光機(jī)
TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊
如果數(shù)據(jù)組很重要,這里有一個(gè)算法:
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(",")))
希望這可以幫助!
添加回答
舉報(bào)
0/150
提交
取消