I am new to firebase, and I am trying to put json object data into my firebase. I know how to put data as a class object into firebase, But I want to put json object data.>
It is so simple to also save JSON value on firebase. Let's say you have called your firebase reference
Firebase ref = new Firebase("https://docs-examples.firebaseio.com/android/saving-data/fireblog");
Then you will pass your data with Map
objects. Map
keeps values with keys. In your case you will have a String
key and JSONObject
value.
Firebase userRef = ref.child("user");
Map userMap= new HashMap();
JSONObject tempObject = new JSONObject();
try{
tempObject.put("birthday","1992");
tempObject.put("fullName","Emin AYAR");
}catch(Exception e){
e.printStackTrace();
}
userMap.put("myUser", tempObject);
userRef .setValue(userMap);