Reading from a simple FireBase Database

前端 未结 3 460
不知归路
不知归路 2021-01-24 06:40

I\'m having some issues reading from a Firebase Database.

I have a pretty simple layout

{
  \"lot\" : {
    \"lot1\" : \"low\",
    \"lot2\" : \"low\",
          


        
3条回答
  •  醉话见心
    2021-01-24 07:12

    you can use typecast to JSONObject and parse the JSONObject

        JSONObject jsonObject= new JSONObject((Map)dataSnapshot.getValue());
    
        JSONObject jsonObj= (JSONObject) jsonObject.get("lot");
    
             for (Object key : jsonObj.keySet()) {
            //based on you key types
            String keyStr = (String)key;
            Object keyvalue = jsonObj.get(keyStr);
    
            //Print key and value
            System.out.println("key: "+ keyStr + " value: " + keyvalue);
    }
    

    if you using java 8 than you use lamada expression.

提交回复
热议问题