Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:10:04+00:00 2026-06-06T22:10:04+00:00

I am creating and sending a JSON Object with jQuery, but I cannot figure

  • 0

I am creating and sending a JSON Object with jQuery, but I cannot figure out how to parse it properly in my Ajax servlet using the org.json.simple library.

My jQuery code is as follows :

var JSONRooms = {"rooms":[]};
       $('div#rooms span.group-item').each(function(index) {
           var $substr = $(this).text().split('(');
           var $name = $substr[0];
           var $capacity = $substr[1].split(')')[0];           
           JSONRooms.rooms.push({"name":$name,"capacity":$capacity});
       });        
       $.ajax({
           type: "POST",
           url: "ParseSecondWizardAsync",          
           data: JSONRooms,        
           success: function() {
               alert("entered success function");
               window.location = "ctt-wizard-3.jsp";
           }
       });

In the servlet, when I use request.getParameterNames() and print it out to my console I get as parameter names rooms[0][key] etcetera, but I cannot parse the JSON Array rooms in any way. I have tried parsing the object returned by request.getParameter("rooms") or the .getParameterValues("rooms") variant, but they both return a null value.

Is there something wrong with the way I’m formatting the JSON data in jQuery or is there a way to parse the JSON in the servlet that I’m missing?

Ask for more code, even though the servlet is still pretty much empty since I cannot figure out how to parse the data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:10:07+00:00Added an answer on June 6, 2026 at 10:10 pm

    The data argument of $.ajax() takes a JS object representing the request parameter map. So any JS object which you feed to it will be converted to request parameters. Since you’re passing the JS object plain vanilla to it, it’s treated as a request parameter map. You need to access the individual parameters by exactly their request parameter name representation instead.

    String name1 = request.getParameter("rooms[0][name]");
    String capacity1 = request.getParameter("rooms[0][capacity]");
    String name2 = request.getParameter("rooms[1][name]");
    String capacity2 = request.getParameter("rooms[1][capacity]");
    // ...
    

    You can find them all by HttpServletRequest#getParameterMap() method:

    Map<String, String[]> params = request.getParameterMap();
    // ...
    

    You can even dynamically collect all params as follows:

    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        String name = request.getParameter("rooms[" + i + "][name]");
        if (name == null) break;
        String capacity = request.getParameter("rooms[" + i + "][capacity]");
        // ...
    }
    

    If your intent is to pass it as a real JSON object so that you can use a JSON parser to break it further down into properties, then you have to convert it to a String before sending using JS/jQuery and specify the data argument as follows:

    data: { "rooms": roomsAsString }
    

    This way it’s available as a JSON string by request.getParameter("rooms") which you can in turn parse using an arbitrary JSON API.


    Unrelated to the concrete problem, don’t use $ variable prefix in jQuery for non-jQuery objects. This makes your code more confusing to JS/jQuery experts. Use it only for real jQuery objects, not for plain vanilla strings or primitives.

    var $foo = "foo"; // Don't do that. Use var foo instead.
    var $foo = $("someselector"); // Okay.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sending an Array of values through Ajax via jQuery with a Play
I'm using a simple ajax-enabled WCF service. I'm creating a string of XML on
I am creating an ajax login and it used to work but for some
I am creating a Web Service using ASP.NET C#. I am sending various data
I'm creating an app. I'm sending the login info using HTTP POST method and
I am creating and sending HTML e-mails. I'm using markup like <table style=background: url('http://example.com/App_Sprites/image.gif');>
I am creating and sending emails using the System.Net.Mail namespace. The smtp.Send(mailMessage) call is
I'm creating a used cars website (written in PHP), and I'm stuck on sending
Creating a simple RPG game, first time using XNA. Trying to get my character
I'm creating a RESTful API that returns JSON or XML depending on the Accept

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.