4

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

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

Then i try to get it with java servlet like this:

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);
    }
}

Inside servlet request string has parameter names:

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

How can i parse request string to original JSON?

Im using embedded jetty server and I want to use "JSON to Object" jetty parser on JSON string

HQCasanova
  • 1,158
  • 1
  • 10
  • 15
user1312837
  • 1,268
  • 1
  • 11
  • 29
  • do u want to parse json to object..try google gson http://code.google.com/p/google-gson/ – Rajesh Nov 21 '12 at 07:33
  • But can i make it without gson dependency? Is there a way to convert query string to original JSON? – user1312837 Nov 21 '12 at 07:37
  • query string to original JSON means..what i know.. "request from browser are converted to java object on server and response java object on server is converted to json string and send the browser"..writing just for reference.. – Rajesh Nov 21 '12 at 07:41
  • 1
    I think this links will help you. http://stackoverflow.com/questions/5245840/how-to-convert-string-to-jsonobject-in-java http://stackoverflow.com/questions/1395551/convert-a-json-string-to-object-in-java – SANN3 Nov 21 '12 at 09:21

1 Answers1

0

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

live example

flexjson library

Tien Nguyen
  • 4,298
  • 9
  • 30
  • 44