Parse HttpServletRequest contains jsonp string

When I try to send a cross-domain jsonp request with:

$.getJSON(url + "?callback=?", value : 'John', record : { value : 'a', list : [ 1, 2 ] }); 

Then I try to get it using a Java servlet as follows:

 public class TestServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String output = request.getParameter("callback") + "({\"response\":\"test\"});"; response.setContentType("application/javascript;charset=utf-8"); PrintWriter out = response.getWriter(); out.println(output); } } 

The inner servlet request string has parameter names:

 _=1353482336546 value=John record[value]=a 

How can I parse the query string to the original JSON?

I use the built-in berth server and I want to use a JSON parser for an object on a JSON string

+4
source share
1 answer

You can use flexjson to parse a json string for an object. Please take a look at:

living example

flexjson library

0
source

Source: https://habr.com/ru/post/1447416/


All Articles