android list获取数据,public List <Model> android中的loadInBackground()方法没有从json中获取数据...

我正在开发一个使用android的应用程序,我试图在我的DataListLoader类中使用loadInBackground()方法获取json数组显示在Listfragment中:public List android中的loadInBackground()方法没有从json中获取数据

class DataListLoader extends AsyncTaskLoader> {

List mModels;

String jsonString;

String name = "Daniel Nyerere", phone = "0652400670";

public DataListLoader(Context context) {

super(context);

loadInBackground();

}

public List loadInBackground() {

// You should perform the heavy task of getting data from

// Internet or database or other source

// Here, we are generating some Sample data

// Create corresponding array of entries and load with data.

final List entries = new ArrayList(50);

StringRequest stringRequest = new StringRequest(

Request.Method.GET, "http://10.0.2.2/webapp/json_get_data.php", new Response.Listener() {

@Override

public void onResponse(String response) {

if (response.trim().contains("server_response")) {

jsonString = response.toString();

try {

JSONObject jsonObject = new JSONObject(jsonString);

JSONArray jsonArray = jsonObject.getJSONArray("server_response");

int count = 0;

while (count < jsonArray.length()) {

JSONObject jo = jsonArray.getJSONObject(count);

name = jo.getString("name");

phone = jo.getString("user_phone");

entries.add(new Model(name, phone));

System.out.println("DATA FROM JSON ARRAY: " + name + " " + phone);

count++;

return;

}

} catch (JSONException e) {

e.printStackTrace();

}

}

}

}, new Response.ErrorListener() {

@Override

public void onErrorResponse(VolleyError error) {

}

});

RequestQueue requestQueue = VolleySingleton.getInstance().getRequestQueue();

requestQueue.add(stringRequest);

entries.add(new Model(name, phone));

return entries;

}

但是,当我尝试的System.out.println运行数据( “数据条目:” +项);来作为空列表,所以没有数据显示在片段活动中。任何人谁可以帮我修复它,以便我从JSON获取数据,因为它消耗了我很多时间

2016-05-29

Nyerere

+0

是你试图检查你的JSON数组长度? –

+0

不,我想从数组中获取数据并将其显示在listfragment中,方法是将它传递给Model类,通过列表 –

+0

您不了解我...您是否检查服务器的答案是否正确?什么是数组长度? –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值