如何查看JsonObjectRequest的网络响应?

时间:2018-04-08 21:15:22

标签: java android android-volley

这是我的要求:

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
  (Request.Method.POST, url, parameters, new Response.Listener<JSONObject>() {

    @Override
    public void onResponse(JSONObject response) {
        ArrayList<String> empresas = new ArrayList<String>();
        for (Iterator<String> it = response.keys(); it.hasNext(); ) {
            String key = it.next();
            try {
                String empresa = (String) response.get(key);
                empresas.add(empresa);
                empresasMap.put(key, empresa);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(EmpresasFetch.this.localContext,
                R.layout.list_mobile, empresas);
        EmpresasActivity.empresasList.setAdapter(adapter);
        EmpresasActivity.empresasList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(EmpresasFetch.this.localContext,
                        parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();

                    /*Intent intent = new Intent(view.getContext(), EmpresasActivity.class);
                    intent.putExtra("segmento", (String) parent.getItemAtPosition(position));
                    localContext.startActivity(intent);*/
            }
        });

    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        System.err.println("It wasn't possible to fetch the server's data.");
        System.err.println(error);
        System.err.println(error.networkResponse);
    }
});

System.err.println(error.networkResponse);返回null:

W/System.err: It wasn't possible to fetch the server's data.
              com.android.volley.ParseError: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
W/System.err: null

我无法访问Android Profiler,因为目标版本低于21.我怎样才能看到从网络服务器返回的字符串??

0 个答案:

没有答案