-2

I want to read JSON web service result.

My web service result is

[{"etkinlikTarihi":123,"eposta":"posta","etkinlikAdi":"ali","etkinlikDetay":"veli","etkinlikId":1},{"etkinlikTarihi":12,"eposta":"posta","etkinlikAdi":"ali","etkinlikDetay":"detay","etkinlikId":2},{"etkinlikTarihi":13,"eposta":"posta","etkinlikAdi":"mali","etkinlikDetay":"detay","etkinlikId":3},{"etkinlikTarihi":13,"eposta":"posta","etkinlikAdi":"mali","etkinlikDetay":"detay","etkinlikId":4}]

But, whenever I try to read with JSONObject in Android, I get a exception...

My code is here,

jsonResponse = new JSONObject(wsEtkinlikListesi);

String etkinlikTarihi = jsonResponse.getString("etkinlikTarihi");

And this is my stack trace:

org.json.JSONException: Value [{"etkinlikAdi":"toplanti","etkinlikDetay":"toplan","etkinlikTarihi":1454648400000,"etkinlikId":5,"eposta":"sefagenel@gmail.com"}] of type org.json.JSONArray cannot be converted to JSONObject

Where is my mistake and how can I correct it?

Eric Brandwein
  • 861
  • 8
  • 23

1 Answers1

1

First try to parse the array and then get every object on it:

JSONArray arr = new JSONArray(jSonResultString);
for (int i = 0; i < arr.length(); i++) {
    JSONObject jsonobject = arr.getJSONObject(i);
    String name = jsonobject.getString("etkinlikTarihi");
    String url = jsonobject.getString("posta");
    ...
}
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97