1 回答

TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以直接從 反序列化。另外,您不需要使用 來(lái)讀取 .嘗試使用 直接解析數(shù)據(jù):JSONInputStreamorg.jsonJSONGson
private Map<String, Quizzes> loadQuizzes(InputStream jsonInputStream) throws IOException {
Gson gson = new GsonBuilder().create();
Type quizzesType = new TypeToken<List<Quizzes>>() {}.getType();
try (InputStreamReader reader = new InputStreamReader(jsonInputStream, StandardCharsets.UTF_8)) {
List<Quizzes> quizzes = gson.fromJson(reader, quizzesType);
return quizzes
.stream()
.collect(Collectors.toMap(Quizzes::getQuizId, q -> q));
}
}
現(xiàn)在,您可以從 中查找對(duì)象。QuizzesMapid
添加回答
舉報(bào)