saving json object to firebase in android

前端 未结 5 1684
独厮守ぢ
独厮守ぢ 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:48

    As suggested here: Convert a JSON String to a HashMap

    you can easily convert your json object/string to a Map (you don't even need to create a POJO):

    Firebase ref = new Firebase(YOUR_FIREBASE_REF);
    Map map = new Gson().fromJson(jsonString, new TypeToken>() {}.getType());
    ref.setValue(map);
    

提交回复
热议问题