1


i got this JSONArray but i cant figure out how to put it in a listview. i figured out the ArrayAdapter but is doesnt give me the right result

[{"id":"1","name":"Joris","sex":"1","birthyear":"1987"},{"id":"2","name":"bjorn","sex":"1","birthyear":"1987"},{"id":"3","name":"Mel","sex":"0","birthyear":"1992"},{"id":"4","name":"Peter","sex":"1","birthyear":"1955"},{"id":"5","name":"Geer","sex":"1","birthyear":"1979"}]

this is my result on the phone in a list after using ArrayAdapter.
Can somebody help me?

{"id":"1","name":"Joris","sex":"1","birthyear":"1987"}
{"id":"2","name":"bjorn","sex":"1","birthyear":"1987"}
{"id":"3","name":"Mel","sex":"0","birthyear":"1992"}
{"id":"4","name":"Peter","sex":"1","birthyear":"1955"}
{"id":"5","name":"Geer","sex":"1","birthyear":"1979"}
JeremyP
  • 84,577
  • 15
  • 123
  • 161
Dragster
  • 13
  • 1
  • 7
  • what do you want to put in list view, i mean name, sex, birthyear etc????? – viv Nov 17 '10 at 15:22
  • 1
    Based on the title of the question, do you think yo have a multi-dimensional array? You do not. You have an array of objects. – Jacob Tomaw Nov 17 '10 at 15:22
  • ok that is one thing i needed to know thats its not a multi array. but i only want the values after ":"-sign (dont know english word). So the real values. This is what came out of a mysql-db from my website. – Dragster Nov 18 '10 at 00:19

2 Answers2

1

This json parsing in java example can help

Bhanu Krishnan
  • 3,726
  • 1
  • 20
  • 40
0

I don't know how you moved round it, but if would have done it this way.

The string you have is a collection of JSON objects, it's JSON array in terms of Java, so first step would be to parse that array and get each row in an ArrayList. This ArrayList shall be ArrayList of String[], where each row shall be an array containing id, sex, birthyear etc.

You can check this post for parsing JSON: JSON Parsing in Android

Next step would be to create a custom listAdapter so that I can pass my created ArrayList and fetch elements from it and display in whatever way I want.

Community
  • 1
  • 1
viv
  • 6,158
  • 6
  • 39
  • 54