Passing JSON via URI

I am trying to create a REST based web service with data encapsulated using JSON. My problem is that when I pass a string version of JSON in a URI, it accesses something like this:% 7B% 22coal% 22: 100,% 22ele% 22: 1500.1% 7D.

I'm wondering if there are any Java functions to convert between escaped and unescaped versions so that I can parse the string.

+2


a source to share


5 answers


You must send some content to the request body. Just send request parameters in URI.



+1


a source


Yes, use URLEncoder and / or URLDecoder .



+1


a source


This will be URLDecoder . But unless you are doing something wrong, you should not use it, since methods in the Servlet API pass already decoded strings.

+1


a source


You don't have to decode the URL-escaped text, the web server does it by itself, it should be completely transparent to you.

As some people have already pointed out, you are using URLDecode to reverse the URL bar

If at some point in your code you are manually avoiding the JSON string that is probably the problem since getting it is encoded 2 times.

0


a source


Your parameters are flat (no lists / objects / etc).

  • For HTTP GET requests, try passing data as request parameters instead of encoded JSON
  • For HTTP POST requests you will have no problem with JSON encoding
0


a source







All Articles