我创建了一个Volley JsonObjectRequest,它向我的REST API发出HTTP请求。但是在打电话之后,它没有响应任何Json。
String JSON_URL = "http://192.168.10.136:8000/api/vehicle";
JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(JSON_URL,null,new Response.Listener<JSONObject>(){
@Override
public void onResponse(JSONObject response){
try {
JSONArray vehicles = response.getJSONArray("vehicles");
for (int i=0;i<vehicles.length();i++)
{
JSONObject vehicle=vehicles.getJSONObject(i);
if(vehicle.getString("type")=="Taxi") {
TaxiList sr1 = new TaxiList();
sr1.setName(vehicle.getString("name"));
sr1.setPhone(vehicle.getString("phone"));
results.add(sr1);
}
}
}catch (JSONException e){
e.printStackTrace();
}
}
},new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
}
});
RequestQueue requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(jsonObjectRequest);
我的REST API是使用Laravel 5.2构建的
执行期间没有显示错误。执行后,日志窗口包含以下消息:
01-14 10:23:44.011 1050-1079/com.psybo.shahi.localareaportal D/Volley: [121] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://192.168.10.136:8000/api/vehicle 0x31e08304 NORMAL 1> [lifetime=4372], [size=804], [rc=200], [retryCount=0]
01-14 10:23:44.538 1050-1050/com.psybo.shahi.localareaportal D/Volley: [1] Request.finish: 6690 ms: [ ] http://192.168.10.136:8000/api/vehicle 0x31e08304 NORMAL 1
01-14 10:24:16.518 1050-1053/com.psybo.shahi.localareaportal W/art: Suspending all threads took: 7.407ms
01-14 10:24:31.773 1050-1053/com.psybo.shahi.localareaportal W/art: Suspending all threads took: 25.889ms
01-14 10:24:40.305 1050-1053/com.psybo.shahi.localareaportal W/art: Suspending all threads took: 8.920ms
01-14 10:24:41.283 1050-1053/com.psybo.shahi.localareaportal W/art: Suspending all threads took: 19.850ms
01-14 10:24:52.957 1050-1053/com.psybo.shahi.localareaportal W/art: Suspending all threads took: 83.792ms
01-14 10:24:58.775 1050-1050/com.psybo.shahi.localareaportal W/PathParser: Points are too far apart 4.000000596046461
01-14 10:24:59.828 1050-1053/com.psybo.shahi.localareaportal W/art: Suspending all threads took: 30.584ms
01-14 10:25:00.767 1050-1050/com.psybo.shahi.localareaportal W/PathParser: Points are too far apart 4.000000596046461
01-14 10:25:01.763 1050-1058/com.psybo.shahi.localareaportal I/art: Background partial concurrent mark sweep GC freed 1634(113KB) AllocSpace objects, 14(26MB) LOS objects, 33% free, 7MB/11MB, paused 1.513ms total 188.700ms
01-14 10:25:03.514 1050-1058/com.psybo.shahi.localareaportal W/art: Suspending all threads took: 10.173ms
01-14 10:25:03.625 1050-1058/com.psybo.shahi.localareaportal I/art: Background partial concurrent mark sweep GC freed 25(1168B) AllocSpace objects, 0(0B) LOS objects, 17% free, 19MB/23MB, paused 1.341ms total 100.224ms
01-14 10:25:04.494 1050-1058/com.psybo.shahi.localareaportal W/art: Suspending all threads took: 10.538ms
01-14 10:25:04.661 1050-1050/com.psybo.shahi.localareaportal I/Choreographer: Skipped 243 frames! The application may be doing too much work on its main thread.
01-14 10:25:08.349 1050-1050/com.psybo.shahi.localareaportal I/Choreographer: Skipped 50 frames! The application may be doing too much work on its main thread.
我需要帮助来解决这个问题
答案 0 :(得分:1)
你必须指定你想要使用URL做什么,无论是Get请求还是Post请求。
JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.GET,JSON_URL,new Response.Listener<JSONObject>(
{
});