Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 3 of 3

Thread: JSON/RPC Help?

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    17

    Question JSON/RPC Help?

    Hey,

    Can anyone help me out on how to actually send a command using the JSON/RPC interface? I think I get the logic:

    1. Create a JSON object, similar to this:

    {"id":1,"method":"slim.request","params":["00:03:0d:d1:70:f4",["play"]]}

    2. Send this command to here (using HttpWebRequest):

    "http://" + hostName + ":" + portNumber + "/jsonrpc.js";

    3. Get the response (using HttpWebResponse)

    4. Pull required data from JSON response (for queries).

    I'm using C#.NET for Windows Phone 7. Has anyone got any sample code for this?

    Here's what I've been messing around with, and I can't even get the object formatted correctly as you can see in the comments:

    Code:
            public void sendCommand(string currentPlayerID, string cmdVal)
            {
                string baseUri = "http://" + hostName + ":" + portNumber + "/jsonrpc.js";
    
                SendCommand command = new SendCommand();
    
                command.id = 1;
                command.method = "slim.request";
                command.@params = new string[] {currentPlayerID, cmdVal};
               
                string output = JsonConvert.SerializeObject(command);
    
                //intended post:
                //{"id":1,"method":"slim.request","params":["00:03:0d:d1:70:f4",["play"]]}
    
                //actual post:
                //{"id":1,"method":"slim.request","params":["00:03:0d:d1:70:f4","play"]}
    
                ResultBlock.Text = output;
                
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(new Uri(baseUri + output));
    
                req.Method = "POST";
                req.Accept = "application/json";
                req.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
    
                SendCommand deserializedProduct = JsonConvert.DeserializeObject<SendCommand>(output);
    
            }

  2. #2

  3. #3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •