2012-11-19 95 views
0

我正在使用Jackson库来解析本地json文件。 当解析按钮按下我有错误:无法反序列化ArrayList

W/System.err(7569): org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of VALUE_NUMBER_INT token 

JSON文件是:

{"surveys":[{"id_survey":"1","question_survey":"Are you happy with the actual government?","answer_yes":"50","answer_no":"20"}],"success":1} 

,使检索的方法是:

final void gettingJson() { 
    final Thread checkUpdate = new Thread() { 
     public void run() { 
     usersController.init(); 
     final StringBuilder str = new StringBuilder("user : "); 
     for (User u : usersController.findAll()) { 
      str.append("\n").append("ID : ").append(u.getId_survey()); 
      str.append("\n").append("Question : ").append(u.getQuestion_survey()); 
      str.append("\n").append("Yes : ").append(u.getAnswer_yes()); 
      str.append("\n").append("No : ").append(u.getAnswer_no()); 

     } 
     runOnUiThread(new Runnable() { 
       public void run() { 
        displayJson.setText(str.toString()); 
       } 
      }); 

     } 
    }; 
    checkUpdate.start(); 
    } 

有什么补充在代码中?难道我做错了什么? 谢谢你的帮助。

+0

如果没有匹配类定义,您的问题将不会被回答:所有可以说的是,所讨论的类期望一个'List',但JSON包含一个数字。 – StaxMan

回答

1

问题解决了,这是由于json文件中的那个字符串"success":1。所以我删除它,现在一切都很好。

+0

是的,这是由无效的JSON引起的。我通常使用一个快速的PHP脚本来生成我的JSON,所以我知道它是有效的。 – Webnet