SyncedObject home = pubnub.sync("home");
SyncedObject thermostat = pubnub.sync("home.living_room.thermostat");
SyncedObject occupants = pubnub.sync("home.occupants");SyncedObject home = pubnub.sync("home");
SyncedObject thermostat = home.child("living_room.thermostat");
SyncedObject occupants = home.child("occupants");If value doesn't exist or cannot be cast to getter's type, null will be returned.
String state = thermostat.getString("state");
// state is a string "on"Integer temperature = thermostat.getInteger("temperature");
// temperature is an integer 68Boolean connected = thermostat.getBoolean("connected");
// temperature is a boolean trueInteger state = thermostat.getInteger("state");
// state is nullHashMap stateMap = home.getMap();ArrayList occupantsList = home.getList("occupants");
ArrayList occupantsList = occupants.getList();// merge(), unlike replace(), will add data to your object WITHOUT truncating existing child data.
JSONObject scoresUpdate = new JSONObject();
scoresUpdate.put("Chauncy", 10);
scores.merge(scoresUpdate);
// or without instantiating SyncedObject
Hashtable<String, Object> args = new Hashtable<String, Object>();
args.put("location", "scores");
args.put("data", scoresUpdate);
pubnub.merge(args, new Callback());// replace(), unlike merge(), will add data to your object, WHILE truncating existing child data.
JSONObject scoresUpdate = new JSONObject();
scoresUpdate.put("Scotty", 3);
scores.replace(scoresUpdate);
// or without instantiating SyncedObject
Hashtable<String, Object> args = new Hashtable<String, Object>();
args.put("location", "scores");
args.put("data", scoresUpdate);
pubnub.replace(args, new Callback());// remove() deletes data
scores.remove();
// or without instantiating SyncedObject
Hashtable<String, Object> args = new Hashtable<String, Object>();
args.put("location", "scores");
pubnub.remove(args, new Callback());// push() appends data to the end of a list container
JSONObject playersUpdate = new JSONObject();
JSONObject player1 = new JSONObject();
player1.put("name", "Randy");
player1.put("weapon", "dagger");
playersUpdate.put("Player_1", player1);
players.push(playersUpdate);
// or without instantiating SyncedObject
Hashtable<String, Object> args = new Hashtable<String, Object>();
args.put("location", "players");
args.put("data", scoresUpdate);
pubnub.push(args, new Callback());