Ich versuche folgende JSON mit Firebase zu analysieren:Parsing ID Ausgabe FirebaseRecyclerAdapter
{
"organizations" : {
"-KS5bLCjQmNSQZDIQkTE" : {
"about" : {
"address" : "teka",
"city" : "sns",
"country" : "South Africa",
"created_at" : 1474358502482,
"name" : "diverse",
"pincode" : "167377",
"state" : "punjab",
"utc" : "2016-09-20 08:01:41"
},
"department" : {
"-KS9LUpZWo5UqtWKJwJ8" : {
"address" : "best",
"name" : "test"
}
}
}
}
}
Hier ist mein Java-Code:
@IgnoreExtraProperties
public class Organizations {
About about;
Department department;
public String getDepartment() {
return department;
}
public static class Department{
public String address;
public String name;
public String getName() {
return name;
}
public String getAddress() {
return address;
}
}
}
FirebaseRecyclerAdapter
fbOrganizationRecycleAdapter = new FirebaseRecyclerAdapter<Organizations, OrganizationHolder>
(Organizations.class, R.layout.list_items_orgnization,OrganizationHolder.class,lastFifty)
{
@Override
protected void populateViewHolder(OrganizationHolder viewHolder, final Organizations model, int position) {
Log.e(TAG, "test " + model.getDepartment().getName());
}
};
Alles ist Parsen in Ordnung, außer Department
. Es gibt mir null department
zurück, wenn ich versuche, model.getDepartment().getName();
zu erhalten.
Wenn die Daten wie folgt aus JSON ist, funktioniert es gut:
{
"organizations" : {
"-KS5bLCjQmNSQZDIQkTE" : {
"about" : {
"address" : "teka",
"city" : "sns",
"country" : "South Africa",
"created_at" : 1474358502482,
"name" : "diverse",
"pincode" : "167377",
"state" : "punjab",
"utc" : "2016-09-20 08:01:41"
},
"department" : {
"address" : "best",
"name" : "test"
}
}
}
}
ich glaube, das Problem mit dem ID
ist. Bitte lassen Sie mich wissen, wie ID zu analysieren "-KS9LUpZWo5UqtWKJwJ8"
aus der folgenden JSON:
"department" : {
"-KS9LUpZWo5UqtWKJwJ8" : {
"address" : "best",
"name" : "test"
}
}
Bitte geben Sie den Mindestcode an t reproduziert das Problem. Wie es jetzt aussieht, wissen wir nicht, wie die 'Department'-Klasse aussieht oder wie Sie die Daten tatsächlich lesen (mit einer Art von Listener oder wie Sie die Referenz für den Adapter einrichten). –
Sie können 'JsonDeserializer' oder' TypeAdapterFactory' schreiben, um es selbst zu parsen. Hier ist ein schönes Beispiel von Jesse Wilson (Gson Contributor) http://stackoverflow.com/a/11272452/1726166 – ytRino