While fetching json data I am getting error:
JSONArray cannot be converted to JSONObject
Code for json generate:
Use this method:
private void showJSON(String response) {
list = new ArrayList<>();
String name = null;
try {
JSONArray jsonObject = new JSONArray(response);
for(int i = 0; i < jsonObject.length(); i++) {
JSONObject obj = jsonObject.getJSONObject(i);
//store your variable
list.add(obj.getString("Name"));
}
// JSONArray result = jsonObject.getJSONArray("");
// JSONObject collegeData = result.getJSONObject(0);
// list.add(jsonObject.getString(collegeData.getString("Name")));
Toast.makeText(getActivity(), name, Toast.LENGTH_LONG).show();
city_list.addAll(list);
adapter.notifyDataSetChanged();
} catch (JSONException e) {
e.printStackTrace();
// Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
}
}