我想从Firebase快照中检索india-margao-pcc-sandeep
之类的串扰节点。
如何在Android中存储或如何检索它?
Firebase searchRef =Ref.child("classtalk");
searchRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
Log.d("djj search",snapshot.toString());
for(DataSnapshot postSnapshot : snapshot.getChildren()){
SchoolSearchModel mSearch = postSnapshot.getValue(SchoolSearchModel.class);
Log.d("djj actual search",mSearch.getClasstalk());
Log.d("djj actual search",mSearch.getClasstalkmembers());
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.d("djj search", firebaseError.getMessage());
}
});
我在Json的数据如下:
{
"india-margao-pcc-sandeep": {
"-Jw6WEO0mNbWR3FgfZBA": {
"admin": "sandeep",
"city": "margao",
"country": "india",
"school": "pcc"
},
"classtalkmembers": {
"-Jw6WEO4IMxm-i0xkxmG": {
"membername": "sandeep"
}
}
},
"india-ponda-rit-sandeep": {
"-Jw6VuRQZmf9PggBRy-q": {
"admin": "sandeep",
"city": "ponda",
"country": "india",
"school": "rit"
},
"classtalkmembers": {
"-Jw6VuRZa1XkQ6Gs6aVO": {
"membername": "sandeep"
}
}
}
}
///////////////////// 这是我得到的错误: " 08-08 10:19:00.266 1857-1857 / com.example.systems_5.firebasedj
E / AndroidRuntime:FATAL EXCEPTION:main
com.firebase.client.FirebaseException: Failed to bounce to type
at com.firebase.client.DataSnapshot.getValue(DataSnapshot.java:183)
at com.example.systems_5.firebasedj.SchoolSearch$1$1.onDataChange(SchoolSearch.java:60) at com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:45) at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
at om.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511) atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
at [Source: java.io.StringReader@41c86e40; line: 1, column: 2] (through reference chain: com.example.systems_5.firebasedj.SchoolSearchModel["classtalkmembers"])
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:575)
at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:46) atcom.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11) atcom.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettablBeanProperty.java:464) at.com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:107) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)atcom.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)atcom.firebase.client.DataSnapshot.getValue(DataSnapshot.java:181)atcom.example.systems_5.firebasedj.SchoolSearch$1$1.onDataChange(SchoolSearch.java:60) at com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:45) at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)at android.os.Handler.handleCallback(Handler.java:615)at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137)at android.app.ActivityThread.main(ActivityThread.java:4918)at java.lang.reflect.Method.invokeNative(Native Method)atjava.lang.reflect.Method.invoke(Method.java:511) atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761) dalvik.system.NativeStart.main(Native Method)
"
答案 0 :(得分:0)
您必须为每种类型创建一个模型类(POJO),以便firebase可以将数据“弹回”给您。