I heve a json url: http://wach.ma/mobile/item.php?id=15236
i want to parse the content and show it in a recyclerview.
everything is good, but when i run it this error happens:
Value Array of type java.lang.String cannot be converted to JSONObject
inside my json file there is a word i want to remove it by the code (because i can't edit the resource)
Array <------------//i want to remove this word
{"articles" : [{"name":"fiat uno ",
"description":"fiat uno
model2002",
"price":"32000dh",
"seen":"5",
"username":"Kech",
"picture":"http:\/\/www.wach.ma\/files\/pictures\/1508420901.png",
"city":"Marrakech",
"phone":"0666353083"}]}
my activity where i want to do that:
public class Details extends AppCompatActivity {
private static final String URL_DATA = "http://wach.ma/mobile/item.php?
id=15236";
private RecyclerView recyclerView2;
private RecyclerView.Adapter adapter;
private List<ListDetail> listDetails;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
recyclerView2= (RecyclerView) findViewById(R.id.recyclerview2);
recyclerView2.setHasFixedSize(true);
recyclerView2.setLayoutManager(new LinearLayoutManager(this));
listDetails=new ArrayList<>();
loadRecyclerViewData();
}
private void loadRecyclerViewData(){
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Chargement...");
progressDialog.show();
StringRequest stringRequest=new StringRequest(Request.Method.GET,
URL_DATA, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.dismiss();
try {
JSONObject jsonObject2=new JSONObject(response);
JSONArray array=jsonObject2.getJSONArray("articles");
for(int i = 0; i<array.length();i++) {
JSONObject o = array.getJSONObject(i);
ListDetail item = new ListDetail(
o.getString("picture"),
o.getString("name"),
o.getString("city"),
o.getString("username"),
o.getString("price"),
o.getString("phone"),
o.getString("description")
);
listDetails.add(item);
}
adapter = new DetailAdapter(listDetails,
getApplicationContext());
recyclerView2.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue= Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
}
i'm sorry for my bad english. thanks in advance