3
{
places: [
{
id: 1,
place:"America",
name: "Robert",
age: "22",
place_lat: "10.017",
place_lon: "76.344"
},
{
id: 1,
place:"America",
name: "Albert",
age: "22",
place_lat: "10.017",
place_lon: "76.344"
},
{
id: 2,
place:"China",
name: "Robert",
age: "22",
place_lat: "10.017",
place_lon: "76.344"
}
,
{
id: 2,
place:"China",
name: "Albert",
age: "20",
place_lat: "10.017",
place_lon: "76.344"
},
{
id: 4,
place:"Paris",
name: "Albert",
age: "20",
place_lat: "10.017",
place_lon: "76.344"
}
],
success: 1

}

Using this json values, I want to show this in a list view, My expected result is

America Name:Robert Age:22 Name:Albert Age:22

China Name:Robert Age:20 Name:Albert Age:20

Paris Name:Albert Age:20

I want to add like this in a list view. But i couldn't make. I got like this in a listview

America Name:Robert Age:22 America Name:Albert Age:22

China Name:Robert Age:20 China Name:Albert Age:20

Paris Name:Albert Age:20

Visal Varghese
  • 436
  • 5
  • 14

2 Answers2

0

Add each object to an array list by using a loop. In each loop check whether the array list contain the object or not before adding . Then you will get a unique Array list of items

Or you can do this by using hash-map (key, value pair) . The key represent the place id and value would be the collection of places

Ajay Venugopal
  • 1,544
  • 1
  • 17
  • 30
0

Since the id is not unique and useless, you can ignore it.

You could parse through the json and create a list beforehand which has all the information. As you loop through each name, add it to an existing country or create a new country (As Ajay said you might want to check for duplicate entries by checking all values).

names["America"].Add (new person ("robert", 22) );
names["America"].Add (new person ("albert", 22) );
names["Paris"].Add( new person ("albert", 20) );

From such an array/dictionary it will be easier to port the information into the format that you are looking for,

Arctic Vowel
  • 1,492
  • 1
  • 22
  • 34