I am trying to use FIREBASE in Android and I have uploaded my JSON created in my FIREBASE account, but something I do not understand is that I do not get the JSON wrong, or the "Retrieving Data" part of the Firebase I'm doing wrong, Here I am the JSON:
{
"Persona": [
{
"nombre": "X",
"apellido": "XX",
"ciudad": "XXX",
"hijoList": [
{
"nombreHijo": "XXXX",
"edadHijo": "XXXXX"
}
]
},
{......}
It connects me and makes me a snapshot without any problem, I show it by toast and it connects me well, but when it comes to using my class Person to get the first and last name, there is something wrong, I teach my class Person :
public class Persona{
private String nombre;
private String apellido;
private String ciudad;
private ArrayList<Hijo> hijoList; // Clase hijo con nombre y edad como atributos
public Persona(){
//empty default constructor, necessary for Firebase to be able to deserialize Persona
}
And then the simple code that just in case I put it in case I have not understood the API FB well:
firebase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
System.out.println("El numero total son: " + dataSnapshot.getChildrenCount());
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
Persona post = postSnapshot.getValue(Persona.class);
System.out.println("JSON FIREBASE: "+post.getNombre() + " - " + post.getApellido());
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(SplashActivity.this, "No se cargaron los personajes debido a: "
+ firebaseError, Toast.LENGTH_SHORT).show();
}
});
What is the problem? can it be because the JSON has Person as an array? Thanks in advance