これはSPARQL の UTF-8 フォーマットに関連していると思いますか?
ここで何が起こったのかを見てみましょう:
- インポーターは、utf-8 でエンコードされた入力 'Chodovská tvrz' を受け取りました。
- utf-8 の場合: '43 68 6f 64 6f 76 73 6b c3 a1 20 74 76 72 7a' (c3 a1 は utf-8 の 'á' です)
- インポーターは、代わりにこれらのバイトを Unicode 文字として読み取ります。
- したがって、'á' の代わりに、'Ã' と '¡' の 2 つの文字 c3 a1 が得られます。
文字列の文字をバイト配列に変換し、そこから新しい文字列を作成することで、これを逆にすることができます。もっと簡単な方法があるはずですが、例を次に示します。
public class Convert
{
public static void main(String... args) throws Exception {
String in = "Chodovsk\u00C3\u00A1 tvrz";
char[] chars = in.toCharArray();
// make a new string by treating chars as bytes
String out = new String(fix(chars), "utf-8");
System.err.println("Got: " + out); // Chodovská tvrz
}
public static byte[] fix(char[] a) {
byte[] b = new byte[a.length];
for (int i = 0; i < a.length; i++) b[i] = (byte) a[i];
return b;
}
}
これを使用するとlist.get(i).get("churchname").toString()
(印刷しているものです)、それらの名前が修正されます。
編集:
または、次を使用します。
String churchname = list.get(i).get("churchname").toString();
String out2 = new String(churchname.getBytes("iso-8859-1"), "utf-8");
これははるかに簡単です。