0
私はこのコード行で問題を抱えている:Gsonデシリアライズの問題UTF-16
try (OutputStreamWriter fileout = new OutputStreamWriter(new FileOutputStream(Paths.get(path.toString(), TAGS_FILE.toString()).toString()), "UTF-16")) {
fileout.write(gson.toJson(imageList, listType));
fileout.flush();
fileout.close();
}
私はUTF-8、元々使っていた、それは罰金、すべて読み込まれ、罰金働いていたが、それに持っていましたいくつかの特殊文字を保持するためにUTF-16に変更してください。それでもファイルは正しく、UTF-8と全く同じように書き込まれます(ただし、特殊文字は入っていません)が、ファイルを別のセッションに読み込もうとすると「BEGIN_ARRAYは期待されますがSTRING ...」と表示されます
方法はありますか?この場合に役立ちます
はまた、:
private final Type listType = new TypeToken<TreeSet<MyClass>>(){}.getType();
TreeSet<MyClass> imageList;
UPDATE:
private void move(File file, Path destination, boolean autoTag) {
String fileName = file.getName();
Matcher numberMatcher = leadingNumbersPattern.matcher(fileName);
// remove leading numbers
while (numberMatcher.find()) {
fileName = clean(fileName, leadingNumbersPattern);
}
Matcher artistMatcher = artistPattern.matcher(fileName);
Matcher newFileNameMatcher = newFileNamePattern.matcher(fileName);
if (artistMatcher.find() && newFileNameMatcher.find()) {
// set artist name
String artist = artistMatcher.group().substring(0, artistMatcher.group().length() - 1);
// set new picture name
String newFileName = newFileNameMatcher.group().substring(1);
Path newPath = Paths.get(destination.toString(), artist); // path to artist folder
new File(newPath.toString()).mkdirs(); // make artist folder
newPath = Paths.get(destination.toString(), artist, newFileName); // make path to new file location
try {
Files.move(file.toPath(), newPath, StandardCopyOption.REPLACE_EXISTING); // move file to new location
MyImage newImage = new MyImage(newPath.toString(), artist, newFileName);
UTF-8は、Unicode標準で* all *文字を表すはずです。おそらく、新しい問題ではなくオリジナルの問題に取り組むことが最善の方法でしょう。 – RealSkeptic
よく@RealSkeptic私はタイ語の文字に遭遇しました...それはjsonファイルにタイの文字ではなく保存していました。文字を正しく書くための提案があれば、私はもっと幸せになるでしょう。 – Kofu
まず、標準のjsonは '\ uXXXX'の形式の文字をサポートすることになっています。したがって、US-ASCIIのJSONでも、タイ語などの文字を使用できます。しかし、あなたの質問を編集して、ファイルに書き込むサンプルクラス、結果のJSON、そして期待したものを追加できますか? – RealSkeptic