我试图检索像德里1这样的特定城市下的学生姓名。该代码在明确指定城市时起作用,但在城市是用户特定变量时不起作用。 JSON -
{
"Schedule" : {
"Delhi 1 " : {
"22" : {
"6" : {
"2017" : "9:00"
}
}
},
"Delhi 2 " : {
"12" : {
"6" : {
"2017" : "5 pm"
}
}
},
"Delhi 3 " : {
"1" : {
"6" : {
"2017" : "10 am"
}
},
"10" : {
"6" : {
"2017" : "11 am"
}
}
}
},
"Students" : {
"Delhi_1" : {
"s1345" : {
"level" : "story",
"name" : "s1345"
},
"s454" : {
"level" : "paragraph",
"name" : "s454"
}
},
"Delhi_2" : {
"abc12" : {
"level" : "story",
"name" : "abc12"
},
"bh45" : {
"level" : "paragraph",
"name" : "bh45"
}
},
"Delhi_3" : {
"ca12" : {
"level" : "story",
"name" : "ca12"
},
"cv23" : {
"level" : "book",
"name" : "cv23"
}
},
"Delhi_4" : {
"bv43" : {
"level" : "story",
"name" : "bv43"
},
"gf43" : {
"level" : "story",
"name" : "cf43"
}
}
},
"Volunteers" : {
"Delhi 1 " : {
"abcd4" : {
"attendance" : 0,
"center" : "Delhi 1 ",
"email" : "a@mail.com",
"phone" : "45878704",
"v_name" : "abcd4"
},
"df3" : {
"attendance" : 0,
"center" : "Delhi 1 ",
"email" : "d@mail.com",
"phone" : "58564543",
"v_name" : "df3"
}
},
"Delhi 2 " : {
"df4" : {
"attendance" : 0,
"center" : "Delhi 2 ",
"email" : "d#mail.com",
"phone" : "48745421212",
"v_name" : "df4"
}
},
"vabc1" : {
"attendance" : 0,
"center" : "Delhi 1 ",
"email" : "s@mail.com",
"phone" : "3799623472",
"v_name" : "vabc1"
}
}
}
Code-
myRef=database.child(center);
myRef.orderByValue().addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot child: dataSnapshot.getChildren()) {
for(DataSnapshot child2: child.getChildren()) {
Stringvalue=child.child("name").getValue().toString();
value.setName(dataSnapshot.child("name").getValue().toString());
System.out.println("Values" + value);
}
}
}