我从维基百科解析了这些数据,并试图从这里只获取字符。但结果是数据前面有UPDATE caduti
SET caduti.eta =
DATEDIFF(YY, caduti.data_nasc, caduti.data_dec) -
CEILING
(0.5 * SIGN (
(MONTH(caduti.data_nasc) - MONTH(caduti.data_dec)) * 50
+ DAY(caduti.data_nasc) - DAY(caduti.data_dec)
)
)
。
" ":" ===고양이의종류=== \ n [[시암고양이]] \ n * [[페르시안네브스카야] ] \ n * [[르르시안]] \ n * [[노르웨이지언포레스트]] \ n * [[키키시앙고라]] \ n * [[아메리칸숏헤어]] \ n * [[브리티시숏헤어]] \ n * [[러시안블루]] \ n * [[뱅갈]] \ n * [[메인쿤]] \ n * [[랙돌]] \ n * [[히말라얀]] \ n * [[재패니[ 밥테일]] \ n * [[오리엔탈숏헤어]] \ n * [[피터볼드]] \ n * [[스코티시폴드]] \ n *스코티시스트레이트\ n * [[하일랜드폴드]] \ n * [[베베리안포레스]] \ n * [[키키시반]] \ n * [[코리안쇼트헤어]] \ n * [[올블랙]] \ n * [[사바나캣]] \ n * [[쿠나]] \ n * [[아비시니안]] \ n *먼치킨"
这是我的代码。
\n*
结果看起来像
\ n 시암고양이
\ n 페르시안
我要删除try {
URL url = new URL("https://ko.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&rvsection=20&titles=%EA%B3%A0%EC%96%91%EC%9D%B4&format=json");
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr);
while(true){
String data = reader.readLine();
if(data == null) break;
result += data;
}
JSONObject obj = new JSONObject(result);
JSONObject query = (JSONObject) obj.get("query");
JSONObject pages = (JSONObject) query.get("pages");
JSONObject pageid = (JSONObject) pages.get("93349");
JSONArray revisions = (JSONArray) pageid.get("revisions");
String catcat = String.valueOf(revisions);
String star = "\n*";
catcat = catcat.replaceAll("\\[\\[","").replaceAll("\\]\\]",",").replaceAll("\\r|\\n", "").replaceAll(star,"");
String[] catcategory = catcat.split(",");
for (int i = 0; i<catcategory.length;i++){
list.add(catcategory[i]);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
。
答案 0 :(得分:0)
除了需要转义星号字符和转义斜杠字符的一行外,所有内容都正确无误
String star = "\\\\n\\*";
str.replaceAll(star, "");
答案 1 :(得分:0)
如何拆分没有特殊字符的解析字符串数据?
尝试使用此段代码,已将其删除 \ n * ,然后您可以将 _result_word 添加到列表中。
for (int i = 0; i < catcategory.length; i++) {
try {
String _result_word = catcategory[i].replaceFirst("\\\\n", "").replace("*", "");
//String _result_word=catcategory[i].replaceFirst("\\\\n", "").replace("*", "").replaceFirst("\\\\n", "").replace("*", "");
System.out.println("" + _result_word);
list.add(_result_word);
} catch (Exception ex) {
System.out.println("Special Exception occurred at index : i = " + i);
ex.printStackTrace();
}
}