Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. JSONArray position = new JSONArray();
  2. position.put(32L);
  3.  
  4. System.out.println("before pub: " + position);
  5. pubnub.publish()
  6. .message(toList(position))
  7. .channel("my_channel")
  8. .async(new PNCallback<PNPublishResult>() {
  9. @Override
  10. public void onResponse(PNPublishResult result, PNStatus status) {
  11. // handle publish result, status always present, result if successful
  12. // status.isError to see if error happened
  13. if(!status.isError()) {
  14. System.out.println("pub timetoken: " + result.getTimetoken());
  15. }
  16. System.out.println("pub status code: " + status.getStatusCode());
  17. }
  18. });
  19.  
  20. public static List<Object> toList(JSONArray array) throws JSONException {
  21. List<Object> list = new ArrayList<Object>();
  22. for(int i = 0; i < array.length(); i++) {
  23. Object value = array.get(i);
  24. if(value instanceof JSONArray) {
  25. value = toList((JSONArray) value);
  26. }
  27.  
  28. else if(value instanceof JSONObject) {
  29. value = toMap((JSONObject) value);
  30. }
  31. list.add(value);
  32. }
  33. return list;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement