我有这样的字符串
 [“ 1505213753057”,“ 1505213854042”,“ 1505537148455”]

我想将其拆分并将值存储到长数组中。

String [] loanId = loanIds.split("\"?,(?=(?:(?:[^\"]*\"){2})*[^\"]*$)\"?");
                Long[] data = new Long[loanId.length];
                for (int i = 0; i < loanId.length; i++) {
                    data[i] = Long.parseLong(loanId[i]);
                }


我正在使用此分离器,但无法正常工作。任何帮助如何实现这一目标?

最佳答案

这应该工作

String loanIds = "[\"1505213753057\",\"1505213854042\",\"1505537148455\"]";

loanIds = loanIds.replaceAll("(\\[\")|(\"\\])", "").replaceAll("\",\"", ",");
String [] loanId = loanIds.split(",");
Long[] data = new Long[loanId.length];
for (int i = 0; i < loanId.length; i++) {
    data[i] = Long.parseLong(loanId[i]);
    System.out.println(data[i]);
}

10-04 17:34