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,它會更容易?另外,爲什麼試圖抓住一切?如果迴應是好的,那麼應該沒有必要,對吧? –