Android JSON解析显示出奇怪的行为

Android JSON解析显示出奇怪的行为,android,json,Android,Json,嘿 我有一个Json字符串: {"responseData":{"days":[{"date":1289430000,"lessons":[{"lesson":"3","classname":"XXXX","oldTeacher":"RUMET","newTeacher":"JAKOB","oldSubject":"0AM","newSubject":"0AM","oldRoom":"104","newRoom":"104 ","comment":""},{"lesson":"4","class

我有一个Json字符串:

{"responseData":{"days":[{"date":1289430000,"lessons":[{"lesson":"3","classname":"XXXX","oldTeacher":"RUMET","newTeacher":"JAKOB","oldSubject":"0AM","newSubject":"0AM","oldRoom":"104","newRoom":"104 ","comment":""},{"lesson":"4","classname":"XXXX","oldTeacher":"RUMET","newTeacher":"JAKOB","oldSubject":"0AM","newSubject":"0APH","oldRoom":"104","newRoom":"107 ","comment":"Verlegtvon"},{"lesson":"8","classname":"XXXX","oldTeacher":"JAKOB","newTeacher":"","oldSubject":"0APH","newSubject":"","oldRoom":"107","newRoom":" ","comment":"Entfall"}]},{"date":1289516400,"lessons":[{"lesson":"1","classname":"XXXX","oldTeacher":"KAIS","newTeacher":"","oldSubject":"0RW1","newSubject":"","oldRoom":"107","newRoom":" ","comment":"Entfall"},{"lesson":"2","classname":"XXXX","oldTeacher":"KAIS","newTeacher":"TRAUN","oldSubject":"0RW1","newSubject":"0BO","oldRoom":"107","newRoom":"107 ","comment":""}]},{"date":1289948400,"lessons":[{"lesson":"5","classname":"XXXX","oldTeacher":"KIES","newTeacher":"","oldSubject":"0RK","newSubject":"","oldRoom":"107","newRoom":" ","comment":"Entfall"}]},{"date":1290121200,"lessons":[{"lesson":"6","classname":"XXXX","oldTeacher":"KIES","newTeacher":"","oldSubject":"0RK","newSubject":"","oldRoom":"107","newRoom":" ","comment":"Entfall"}]}]},"responseDetails":null,"responseStatus":200}
为了更好地理解过去的代码

我将其解析为条目对象列表(SPEntry):

公共类入口解析{
数组列表;
公共入口解析(上下文ctx,字符串par_json)
{
尝试
{
列表=新的ArrayList();
JSONArray数组=新的JSONArray(par_json);
对于(inti=0;i
我的问题是图片设置显示了一种奇怪的行为。在第二个课程元素中,我没有图片,在所有其他情况下,我只得到“Entfall”图片。 资源中的图片是不同的

请帮忙

列表的屏幕截图:


在json字符串中的7个课程条目中,只有一个被使用过一次,那就是
Verlegtvon
(这也是第二个条目)。我猜想在json字符串中的7个课程条目中,drawable
R.drawable.verlegt
有问题,其中只有一个条目被使用过一次,那就是
Verlegtvon
(这也是第二个条目)。我猜想drawable
R.drawable.verlegt
有问题

if(entry.comment.equals("Entfall")){
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.entfall);
                        }
                        if(entry.comment.equals("Betreuung")){
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.betreung);
                        }
                        if(entry.comment.equals("Verlegtvon")){
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.verlegt);
                        }
                        else
                        {
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.empty);
                        }
如果仔细查看代码,最后会得到两个图像,要么是
空的
,要么是
verlegtvon
,使用else If解决问题。尝试下面的代码,我刚刚添加了
else If

if(entry.comment.equals("Entfall")){
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.entfall);
                        }
                        else if(entry.comment.equals("Betreuung")){
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.betreung);
                        }
                        else if(entry.comment.equals("Verlegtvon")){
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.verlegt);
                        }
                        else
                        {
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.empty);
                        }
如果仔细查看代码,最后会得到两个图像,要么是
空的
,要么是
verlegtvon
,使用else If解决问题。尝试下面的代码,我刚刚添加了
else If

if(entry.comment.equals("Entfall")){
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.entfall);
                        }
                        else if(entry.comment.equals("Betreuung")){
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.betreung);
                        }
                        else if(entry.comment.equals("Verlegtvon")){
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.verlegt);
                        }
                        else
                        {
                            entry.picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.empty);
                        }

把这个if(entry.comment.equals(“Verlegtvon”){entry.picture=BitmapFactory.decodeResource(ctx.getResources(),R.drawable.entfall);}放在这里,检查第二个元素是否也有相同的图像。Yashwanth Kumar是对的,用if-else代替简单的if。如果第二个元素(列表行)有相同的图像那么您就有了获取drawable.put的问题,如果(entry.comment.equals(“Verlegtvon”){entry.picture=BitmapFactory.decodeResource(ctx.getResources(),R.drawable.entfall);}检查第二个元素是否也有相同的图像。Yashwanth Kumar正确使用if-else,而不是简单的if。如果第二个元素中有相同的图像(列表行)那么你就有了画图的问题。为什么我之前已经有了if-else部分,现在只显示了第二个图像呢?当它与填充listView有关时,有时图像会在listView中重复。寻找类似的问题,这会解决问题。为什么我之前和那里都有if-else部分呢只是显示的第二个图像它与填充listView有关,有时图像会在listView中重复。查找类似的问题,这将解决问题。更改if条件时不会出现问题更改if条件时不会出现问题