i need to pass the response string by assigning value to the string data to another method out side the OnResponse() scpoe so that i can return a JSONObject from it by calling that method but it always returns null
all i need is to get JSONObject from Volley stringrequest as the response is a xml "
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">........</string>
Here is my code
static String data;
private void driverByIdStringRequest(int ID,final Context context){
RequestQueue queue = VolleySingleton.getInstance(context.getApplicationContext()).getRequestQueue();
// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url+ID,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
response = response.replaceAll("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "");
response = response.replaceAll("<string xmlns=\"http://tempuri.org/\">", "");
response = response.replaceAll("</string>", "");
String data = response.substring(40);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("Error : ", error.toString());
}
});
VolleySingleton.getInstance(context).addToRequestQueue(stringRequest);
}
public JSONObject GetDriverById(int ID,Context context){
driverByIdStringRequest(ID, context);
JSONObject json = JSONObject(data);
return json;
}