JSON Problem?
#1
So I'm trying to get my Java app to use the JSON stuff and I'm having trouble. I've tested the setup with "Simple REST Client" in Chrome and it works great.

URL = http://localhost:8080/jsonrpc

Message = {\"jsonrpc\": \"2.0\", \"method\": \"AudioPlayer.PlayPause\", \"id\": 1}

Print out of message being sent = {"jsonrpc": "2.0", "method": "AudioPlayer.PlayPause", "id": 1}

And when I try this, I get this:
Code:
{
   "error" : {
      "code" : -32700,
      "message" : "Parse error."
   },
   "id" : 0,
   "jsonrpc" : "2.0"
}

What am I doing wrong?
Reply
#2
Please post a full Debug Log when the fail is occuring
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#3
Only relevent part I could find:

Quote:14:04:45 T:6636 M:1282002944 ERROR: JSONRPC: Failed to parse ''

So is it getting a null value?
Reply
#4
You are most likely not doing a POST with the correct data is my guess.

Without the java code its hard to tell (and just a note for next time, pastebin the entire log. You found what I was wondering about but thats not always the case Smile )

Cheers,
Tobias
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#5
My Java code is here: http://pastebin.com/HSk8iWfr

I am really confused, this code works fine for other programs...
Reply
#6
The error message looks to me as if XBMC receives an empty HTTP request. I am absolutely no Java expert so I can't say anything about your code but the jsonrpc request string looks correct. BUT I would recommend to use an existing json (or even jsonrpc) library which allows you to create the requests as objects and then print them. That will make your life so much easier and will avoid problems with badly formed requests. I bet there are quite a few json(-rpc) libraries for java out there.

What I would do is fire up Wireshark and take a closer look at those HTTP requests you send to XBMC. If their content is empty or the Content-Length has a wrong value we'll know that the problem is somewhere in your code and not XBMC.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#7
Montellese Wrote:What I would do is fire up Wireshark and take a closer look at those HTTP requests you send to XBMC. If their content is empty or the Content-Length has a wrong value we'll know that the problem is somewhere in your code and not XBMC.

Great idea, but we already know it's getting a blank request. Huh

Guess I'll give the Apache httpcommons a shot. Thanks for the help so far guys.
Reply
#8
Ok I have finally figured it out. I'll leave the code here to help out any other beginners!

http://pastebin.com/VUFP6Bst
Reply

Logout Mark Read Team Forum Stats Members Help
JSON Problem?0