我是android开发的新手。
我正在尝试将数据从json string
保存到数据库中>
[{ "question": "Who is the 'Modern Love' rock star singer?", "imageUrl": "https://postimg.cc/2VL1Y1jd", "answerOptions": [ "Jimi Hendrix", "David Bowie", "Jim Morrison", "Elvis Presley" ], "correctAnswer": "David Bowie" }]
并且在mainActivity
onCreate
中,我有:
for (int i = 0; i < list.size(); i++) { Quiz quiz = list.get(i); quiz.save(); }
效果很好,因此在我调试时有:
但是当我查看数据库文件时,缺少answerOptions
的子列表:
因此,当我尝试runOnUiThread
时,litePal.findall
处的列表与Quiz.class
不对应
runOnUiThread(new Runnable() { @Override public void run() { List<Quiz> list = LitePal.findAll(Quiz.class); QuizAdapter quizAdapter = new QuizAdapter(list, MainActivity.this); RecyclerView recyclerView = findViewById(R.id.recyclerView); recyclerView.setAdapter(quizAdapter); } });
class Quiz extends LitePalSupport { String question; String imageUrl; String [] answerOptions; String correctAnswer; }
此方法是否有可能的解决方案/替代方法?
我是android开发的新手。我正在尝试将数据从json字符串[{“ question”:“谁是'Modern Love'摇滚明星歌手?”,“ imageUrl”:“ https://postimg.cc / ...]保存到数据库中。 >
我通过更改数据结构解决了这个问题:
[{
"question": "Who is the 'Modern Love' rock star singer?",
"imageUrl": "https://postimg.cc/2VL1Y1jd",
"one": "Jimi Hendrix",
"two": "David Bowie",
"three": "Jim Morrison",
"four": "Elvis Presley",
"correctAnswer": "David Bowie"
}]