Android Volley - 没有来自StringRequest的回复

时间:2015-12-31 09:19:02

标签: android json connection android-volley

使用 Android Volley 时,我无法获得for (int i =0; i<[self.calenderDates count]; i++) { NSString * currentDate = self.calenderDates[i]; for (int j =0; j<[self.papikerCalender count]; j++) { NSString * papikDate = [self.papikerCalender[j] valueForKey:@"strat_date"]; if ([currentDate isEqualToString:papikDate]) { [self.rowData addObject:self.papikerCalender[j]]; [self.dataDictionay setObject:self.rowData forKey:currentDate]; } } } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSString * currentDate = self.calenderDates[section]; NSArray * dicDate = [self.dataDictionay valueForKey:currentDate]; return [dicDate count]; } 响应。没有错误也没有成功的响应(JSON)。我使用StringRequest从 Google Map API Android V2 中获取JSON文本。这里是代码

Log.d("logr=",_response);

解决此问题的任何方法?

2 个答案:

答案 0 :(得分:7)

你在哪里实际执行请求?您必须add()将其发送给Volley&#39; RequestQueue,否则请求将无法发送。

// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);

String url = urla + x + "," + y + urlb;

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
        new Response.Listener<String>() {
            @Override
            public void onResponse(String _response) {

                Log.d("logr=",_response);

            }
        }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {

        // Error handling
        Log.d("log2=", error.toString());
        Log.e("log3=", error.toString());
    }
});
//excecute your request
queue.add(stringRequest);

在此处查看更多内容:Learn volley

答案 1 :(得分:0)

试试这个:

requestQueue = Volley.newRequestQueue(getActivity().getApplicationContext());
final StringRequest stringRequest = new StringRequest(Request.Method.POST, urlString, new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
            strr = response;
            pDialog.hide();
        }
    }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
            pDialog.hide();
            Log.e("Volley", "ERROR");
        }
   });
requestQueue.add(stringRequest);