As @Jesse Amano推薦s,你可能會逃避使用JSON。下面是這樣做的另一種粗暴的方式:
String s = "('1494576','16268568','5150022241','Flour','Pillsbury','2 For $5.00','5','8/20/2016','80','Best All Purpose Unbleached Enriched','Demoulas/Market Basket','2','itemlink')";
String[][] temp = ...;
boolean inside = false;
boolean end = false;
int index = 0;
for(int i = 0; i < s.length(); i ++){
if(s.substring(i, i + 1).equals("'")){
inside = !inside; //determines if we are between ''
if(end) index ++;
end = !end; //determines if this is the closing '
}
else{
if(inside) temp[0][index] += s.substring(i, i +1);
}
}
由什麼分開?空間?一個空字符串?字面上兩個單引號? – vlaz
你能把這個清晰可辨嗎?儘管我認爲我有一個想法,但我不知道你想說什麼。 –
如果您將'('和')'轉換爲'['和']',那麼您可能只需使用JSON解析器庫就可以了,它會爲您構建(一維)數組。 –