I have a problem to parsing from JSON to Listview in Android. This is an example of data from JSON :
[{
\"area\": \"Kebon Jeruk\",
\"city\": \"Jakarta\"
JSONArray arr = new JSONArray(yourJSONresponse);
List<String> list = new ArrayList<String>();
for(int i = 0; i < arr.length(); i++){
String info = arr.getJSONObject(i).getString("area") + arr.getJSONObject(i).getString("city");
list.add(info);
}
And then just turn the List into an Array of Strings, and use an adapter to fill the ListView
like so:
ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.ListView,StringArray);
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);
make changes in ur layoutxml file take two text boxes beside this will work
Remaining on your own
try {
ArrayList<User> list = new ArrayList<>();
JSONArray array = new JSONArray(url);
for (int i = 0; i <array.length() ; i++) {
JSONObject jsonObject = array.optJSONObject(i);
String area = jsonObject.optString("area");
String city = jsonObject.optString("city");
list.add(new User(area,city));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
class User {
String area;
String city;
public User(String area,String city){
this.area=area;
this.city=city;
}