Guest User

JSON

a guest
Jan 22nd, 2014
42
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. For example, I can pass a JSON object from my main device (PC) to my second screen device (tablet) using something like websockets.
  2.  
  3. When I was using it for media players, I would click on a movie, which then sends a JSON object to the player (the PC). That object has all of the info the player that it needs to get going:
  4.  
  5. // Passed in as a parameter, from the tablet, to the video player (PC)
  6. MovieObject{
  7.     Title: Independance Day,
  8.     Audio: Dolby 5,
  9.     URL:   www.PlayIndependanceDayMovie.com,
  10.     ImageURL: wwww.PlayIndependanceDayMovie.com/CoverArt,
  11.     Cast: Actor 1, Actor2, Actor 3
  12. }
  13.  
  14.  
  15.  
  16. // On the video player (PC side) you run a for loop, which loops through the data, and displays it on screen
  17.  
  18. PlayMovie function(MovieObject){
  19.  
  20.     movieTitle = MovieObject.Title
  21.     url = MovieObject.URL
  22.     // Gets cast of actors
  23.     for (var i, i = MovieObject.Cast.length, i++){
  24.         actor = MovieObject.Cast.Length
  25.     }
  26. }
  27.  
  28. Once you have that URL, you can play the movie :)
  29.  
  30. But imagine doing the same thing with controls:
  31.  
  32. On your tablet, if you press the "right" arrow it passes a string to the PC, which parses the string, and acts accordingly:
  33.  
  34. // On the PC side:
  35. handleInput function (inputStringFromTablet){
  36.  
  37.     switch(inputStringFromTablet) {
  38.     case right:
  39.         fastForward();
  40.         break;
  41.     case left:
  42.         rewind();
  43.         break;
  44.     default:
  45.  
  46. }
RAW Paste Data