Android的JSON到列表视图 [英] android json to listview

查看:140
本文介绍了Android的JSON到列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Android和JSON工作。我来了,到目前为止,但我的设置ID在arraylist.The错误将在json_data.getInt(ID),

sombody能帮我

 公共无效klussenlijst()
    {
ArrayList的<串GT;结果=新的ArrayList<串GT;();
        的JSONObject json_data;
        MySQL客户端=新的MySQL(HTTP://www.****************/klussen.php actie = klussen?);        尝试{
            client.Execute(RequestMethod.POST);
        }赶上(例外五){
            e.printStackTrace();
        }        串响应= client.getResponse();        尝试{;
        JSONArray jArray =新JSONArray(响应);
             的for(int i = 0; I< jArray.length();我++){
             json_data = jArray.getJSONObject(ⅰ);
             results.add(json_data.getInt(ID),(串)json_data.get(影片名称)的toString());
            }
             filllist();
             }
             赶上(JSONException E){
                 e.printStackTrace();
             }    }


解决方案

不知道关于你的MySQL()方法和巨大的缺乏错误处理,但你确信你的项目已经允许INTERNET权限的Andr​​oidManifest.xml文件?听起来好像你调用getInt不是int。

I working with android and JSON. I came so far, but I can's set the ID in the arraylist.The error will be in "json_data.getInt("ID")"

Can sombody help me

    public void klussenlijst()
    {
ArrayList<String> results = new ArrayList<String>();
        JSONObject json_data;
        mysql client = new mysql("http://www.****************/klussen.php?actie=klussen");

        try {
            client.Execute(RequestMethod.POST);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String response = client.getResponse();

        try{;
        JSONArray jArray = new JSONArray(response);
             for(int i=0;i<jArray.length();i++){
             json_data = jArray.getJSONObject(i);
             results.add(json_data.getInt("ID"),(String) json_data.get("titel").toString());
            }
             filllist();


             }
             catch(JSONException e){
                 e.printStackTrace();
             }

    }

解决方案

Not sure about your mysql() method and the huge lack of error handling, but are you sure that your project has allowed for INTERNET permissions in your AndroidManifest.xml file? Sounds to me like your getInt is not an int.

这篇关于Android的JSON到列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆