将Json字符串转换为json数组时出错

时间:2015-11-13 07:03:21

标签: android json android-listview

我正在做一个需要从mysql数据库填充listview的应用程序,我参考了本教程。但我收到错误消息“无效响应”,它来自json字符串的catch块。任何人都可以看看这个并帮助我Tutorial Link

 try {
        // convert json string to json array
        JSONArray aJson = new JSONArray(sJson);
        // create apps list
        List<Application> apps = new ArrayList<Application>();

        for(int i=0; i<aJson.length(); i++) {
            JSONObject json = aJson.getJSONObject(i);
            Application app = new Application();
            app.setTitle(json.getString("app_title"));
            app.setTotalDl(Long.parseLong(json.getString("total_dl")));
            app.setRating(Integer.parseInt(json.getString("rating")));
            app.setIcon(json.getString("icon"));

            // add the app to apps list
            apps.add(app);
        }

        //notify the activity that fetch data has been complete
        if(listener != null) listener.onFetchComplete(apps);
    } catch (JSONException e) {
        msg = "Invalide Response";
        if(listener != null) listener.onFetchFailure(msg);
        return;
    }

0 个答案:

没有答案