/ / Retrieve Arraylist von jsonobject - Android, Json, Arraylist

Abrufen von Arraylist von jsonobject - Android, Json, Arraylist

Ich bin neu bei Android und brauche Hilfe beim Abrufen ArrayList von einem JSONObject und ein Element hinzufügen. Ich habe ein JSON-Objekt X, das von der Form ist {"a":[],"b":[],...}. woher [ ] repräsentiert ein ArrayList von "B" s, die ich definiert habe. Ich möchte ein Element zu einem der hinzufügen ArrayList in X vorhanden

Ich habe getan:

B temp = new B();
x.get("string").add(B)

Dies ist der Fehler:

(176, 31) Fehler: Inkompatible Typen benötigt: ArrayList gefunden: Objekt

Vielen Dank!

Antworten:

0 für die Antwort № 1

Sie können die Array-Liste nicht vom JSON abrufen, da JSON ein für Menschen lesbarer Datentyp ist. Du kannst das so machen:

ArrayList<B> list = new ArrayList();
B b= new B();
b.setB(x.getString("Key"));
list.add(b);

b.set("");  is a method could be in your class to set the value of B
x.getString(""); is for getting String type value from the JSON on a specified key