因此,我计划将输入的数据存储到 JSON 文件中,并且希望将该 JSON 文件存储到手机的本地存储中。但是我的代码中有这个错误。这是关于 JsonWriter。谁能帮我?
// THIS IS MY CODE
private void writeToFile(OutputStream out, List<Wordbank> wordList) throws IOException{
JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
writer.setIndent(" ");
writeWordbankArray(writer, wordList);
writer.close();
}
public void writeWordbankArray(JsonWriter writer, List<Wordbank> wordList) throws IOException{
writer.beginArray();
for(Wordbank wl : wordList){
writeWordbank(writer, wl);
}
writer.endArray();
}
public void writeWordbank(JsonWriter writer, Wordbank wordbank) throws IOException{
writer.beginObject();
writer.name("English").value(wordbank.getEnglish());
writer.name("Cebuano").value(wordbank.getCebuano());
writer.name("Pronounciation").value(wordbank.getPronounciation());
writer.name("POS").value(wordbank.getPos());
writer.name("Audio").value(wordbank.getAudio());
if(wordbank.getImage() != null || wordbank.getFx() != null){
writer.name("Picture").value(wordbank.getImage());
writer.name("Effect").value(wordbank.getFx());
}else{
writer.name("No name").nullValue();
}
writer.endObject();
}
// 下面是错误
2018-10-18 18:48:52.372 4965-4965/com.example.sampleFile/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sampleFile, PID: 4965
以上是错误。我需要这方面的帮助,请帮帮我!
繁星淼淼
白板的微信
相关分类