本文介绍了无法从服务器获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从服务器获取数据,我已经完成了所有编码部分,我得到的状态码是200(成功),但是没有获取数据.
I am trying to get data from server, I have done all the coding part I am getting status code is 200 (success) but not getting data.
这是我的JSON数据:
{
"status": 200,
"data": [
{
"id": "1",
"company_id": "8",
"customer_id": "17",
"driver_id": null,
"city_id": "2",
"vehicletype_id": "4",
"status": "Pending",
"source_long": "77.59505250000007",
"source_lat": "12.9998698",
"dest_long": "77.62877609999998",
"dest_lat": "12.946679",
"source": "Jayamahal, Bengaluru, Karnataka, India",
"destination": "Ejipura Bus Stand, Ejipura Main Road, Ejipura, Bengaluru, Karnataka, India",
"bookingtime": "2016-06-14 06:55:38"
}
]
}
这是我获取数据的代码:
JsonObjectRequest jor = new JsonObjectRequest(Request.Method.GET, OPEN_BOOKINGS_URL, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
String string = null;
JSONArray ja =null;
try {
Toast.makeText(getContext(), "You are in Try Block", Toast.LENGTH_SHORT).show();
ja=response.getJSONArray("data");
if(ja!=null)
{
Toast.makeText(getContext(), "Ja is not null with data", Toast.LENGTH_SHORT).show();
for (int i=0; i<ja.length(); i++)
{
Toast.makeText(getActivity(), "for loop", Toast.LENGTH_SHORT).show();
JSONObject jo = ja.getJSONObject(i);
Toast.makeText(getActivity(), jo.toString(), Toast.LENGTH_SHORT).show();
}
}
else
{
tv.setText("ja is null");
// Toast.makeText(getActivity(), "ja is null", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
Toast.makeText(getActivity(), response.toString(), Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
tv.setText(error.toString());
}
});
rq = Volley.newRequestQueue(getContext());
rq.add(jor);
}
在代码中,我写了敬酒来检查我的代码块是否正在执行.
In the code I have written toast to check whether my code block is executing or not.
我正在获取数据,
{
"status": 200,
"data": [
{}
]
}
推荐答案
您没有从服务器端获取数据,因此没有任何问题.您应该向服务器端检查为什么不发送数据.你做得很好...
You are not getting Data from server side, there is no issue by your side..You should check to server side why not sending data..you did well...
这篇关于无法从服务器获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!