1
当我调用getData.It似乎很难从onResponse中获取结果。我知道它不能以目前的方式工作。有谁能帮我解决这个问题吗?不执行Volley JSON onResponse函数
的getData()
private void getData(){
//Creating a string request
StringRequest stringRequest = new StringRequest(SPINNER_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Log.d("Country_name","hi");
JSONObject j = null;
try {
//Parsing the fetched Json String to JSON Object
j = new JSONObject(response);
//Storing the Array of JSON String to our JSON Array
result = j.getJSONArray(JSON_ARRAY);
Log.v("xxxxx",result.toString());
String mysh=result.toString().substring(1, result.toString().length()-1);
JSONArray jsonArray = new JSONArray(mysh);
//Calling method getCountry to get the country from the JSON Array
getCountry(jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
//Creating a request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(stringRequest);
}
什么响应,U从web服务获得。你可以添加json响应吗? – W4R10CK
onErrorResponse()怎么样?是不是因为一些错误而被称为? – abbath
也许如果你做一个jsonRequest而不是一个StringRequest,它会更容易?另外,为什么试图抓住一切?如果回应是好的,那么应该没有必要,对吧? –