I have android app . in that app I'm posting some string data on server and get some response. Problem is ,I'm receiving the response in jsonstring,but I want this data in json array. althouugh when I'm using JsonArrayRequest ,it didn't allow post method in parameter and then my web service is not worked. So I'm stick with StringRequest and service works ok but complete response returns as a whole string.So I'm unable to display my data my list view . So how to resolve this issue?
Here is my code:
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(NewSearchPeople.this, response, Toast.LENGTH_LONG).show();
// search1();
try {
JSONArray jsonArray = new JSONArray(response);
for(int i=0;i<jsonArray.length();i++){
JSONObject obj = jsonArray.getJSONObject(i);
Movie movie = new Movie();
movie.setTitle(obj.getString("fullname"));
movie.setThumbnailUrl(obj.getString("image"));
movie.setRating(obj.getString("location"));
movie.setGenre(obj.getString("Description"));
movie.setYear(obj.getInt("id"));
movieList.add(movie);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(NewSearchPeople.this, error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("fullname", "pooja");
return params;
}
};
Here is json response:
[
{
"id":"442",
"fullname":"xyz(18 yr)",
"image":"\/2017-02-0823:49:521486619389674.jpg",
"location":"lkn","Description":null
},
{
"id":"443",
"fullname":"abc(28 yr)",
"image":"\/2017-02-0823:51:381486619493934.jpg",
"location":"md","Description":null
},
{
"id":"444",
"fullname":"Arya(25 yr)",
"image":"\/2017-02-0823:52:251486619540695.jpg",
"location":"ud","Description":null
}
]