saving json object to firebase in android

前端 未结 5 1685
独厮守ぢ
独厮守ぢ 2021-01-02 08:07

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.

5条回答
  •  温柔的废话
    2021-01-02 08:52

    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);
    

提交回复
热议问题