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 9300857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:53:02+00:00 2026-06-18T22:53:02+00:00

I have a situation. I’m creating a normal JavaScript array that contains a number

  • 0

I have a situation. I’m creating a normal JavaScript array that contains a number of arrays. Since JavaScript is used completely, request.setAttribute() can’t be used. So I’ doing JSON.stringify(<array>) and passing the String as a parameter to a URL. This is how I’m populating my normal JavaScript array-

var arrayOfArrays = new Array();

for(var i=0;i<agent.length;i++){    
        var arrayOfStrings = new Array();
        arrayOfStrings[0] = agent[i].comp;
        arrayOfStrings[1] = agent[i].ip;
        arrayOfStrings[2] = agent[i].port;
        arrayOfStrings[3] = agent[i].username;
        arrayOfStrings[4] = agent[i].password;      

            arrayOfArrays[i] = arrayOfStrings;
}
var agents = JSON.stringify(arrayOfArrays);
// and I'm passing the agents variable as a parameter to a URL.

In the second page, I’m getting the Stringified value using request.getParameter() and trying to convert it to a Java array using the classes and methods of net.sf.json package and continuing with my logic.

The following is the array of arrays I’ve created which is of the form [[...],[...],[...], . . ]–

"[[\"hari2\", \"2.2.2.2\", \"222\", \"2gsz3dg\", \"sdfg2sd3\"], [\"fhf\", \"1.4.5.6\", \"678\", \"gjh\", \"gfhjgf\"], [\"hari1\", \"1.1.1.1\", \"123\", \"sdfg\", \"w34tr5\"], [\"ch\", \"1.1.1.1\", \"123\", \"ghf\", \"dgjyt\"], [\"hari\", \"1.2.3.4\", \"324\", \"xcfhd\", \"serteg34g\"], [\"hari5\", \"5.5.5.5\", \"555\", \"555\", \"555\"], [\"hari4\", \"4.4.4.4\", \"444\", \"444\", \"444\"], [\"hari3\", \"3.3.3.3\", \"333\", \"sfse\", \"3rw\"], [\"hari6\", \"6.6.6.6\", \"666\", \"666\", \"666\"]]"

Here is my logic for converting from String to array-

String agents = request.getParameter("agents");

System.out.println("Agents before removing \" :: " + agents);
if (agents.startsWith("\"") && agents.endsWith("\"")) {
    String agentsTemp = agents.replaceFirst("\"", "");
    agents = agentsTemp.substring(0, agentsTemp.length()-1);
    System.out.println("Agents after removing \" :: " + agents);
}
// applied the above logic as i had got "Invalid JSON String" Exception

if(agents != null && agents.length() > 2) {
    net.sf.json.JSONArray arrayOfArrays = (net.sf.json.JSONArray) net.sf.json.JSONSerializer.toJSON(agents); 

    for(int i=0; i<arrayOfArrays.size();i++) {
        net.sf.json.JSONArray arrayOfStrings = (net.sf.json.JSONArray) arrayOfArrays.get(i);

        String pgData = arrayOfStrings.getString(0);
        String user = arrayOfStrings.getString(3);
        String pwd = arrayOfStrings.getString(4);
        int portInt = Integer.parseInt(arrayOfStrings.getString(2));
        String hostIP = arrayOfStrings.getString(1);

                    // business logic continued
    }
} else {
    // throw exception
}


net.sf.json.JSONException: Missing value. at character 2 of [[\"hari2\", \"2.2.2.2\", \"222\", \"2gsz3dg\", \"sdfg2sd3\"], [\"fhf\", \"1.4.5.6\", \"678\", \"gjh\", \"gfhjgf\"], [\"hari1\", \"1.1.1.1\", \"123\", \"sdfg\", \"w34tr5\"], [\"ch\", \"1.1.1.1\", \"123\", \"ghf\", \"dgjyt\"], [\"hari\", \"1.2.3.4\", \"324\", \"xcfhd\", \"serteg34g\"], [\"hari5\", \"5.5.5.5\", \"555\", \"555\", \"555\"], [\"hari4\", \"4.4.4.4\", \"444\", \"444\", \"444\"], [\"hari3\", \"3.3.3.3\", \"333\", \"sfse\", \"3rw\"], [\"hari6\", \"6.6.6.6\", \"666\", \"666\", \"666\"]]

What is it expecting there? If there is any easier way to solve this issue, I’m open to suggestions.

  • 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-18T22:53:04+00:00Added an answer on June 18, 2026 at 10:53 pm

    Just use JSON.parse().

    This code:

    JSON.parse("[[\"hari2\", \"2.2.2.2\", \"222\", \"2gsz3dg\", \"sdfg2sd3\"], [\"fhf\", \"1.4.5.6\", \"678\", \"gjh\", \"gfhjgf\"], [\"hari1\", \"1.1.1.1\", \"123\", \"sdfg\", \"w34tr5\"], [\"ch\", \"1.1.1.1\", \"123\", \"ghf\", \"dgjyt\"], [\"hari\", \"1.2.3.4\", \"324\", \"xcfhd\", \"serteg34g\"], [\"hari5\", \"5.5.5.5\", \"555\", \"555\", \"555\"], [\"hari4\", \"4.4.4.4\", \"444\", \"444\", \"444\"], [\"hari3\", \"3.3.3.3\", \"333\", \"sfse\", \"3rw\"], [\"hari6\", \"6.6.6.6\", \"666\", \"666\", \"666\"]]");
    

    Outputs the correct array of arrays.:

    [
        ["hari2", "2.2.2.2", "222", "2gsz3dg", "sdfg2sd3"],
        ["fhf",   "1.4.5.6", "678", "gjh",     "gfhjgf"],
        ["hari1", "1.1.1.1", "123", "sdfg",    "w34tr5"],
        ["ch",    "1.1.1.1", "123", "ghf",     "dgjyt"],
        ["hari",  "1.2.3.4", "324", "xcfhd",   "serteg34g"],
        ["hari5", "5.5.5.5", "555", "555",     "555"],
        ["hari4", "4.4.4.4", "444", "444",     "444"],
        ["hari3", "3.3.3.3", "333", "sfse",    "3rw"],
        ["hari6", "6.6.6.6", "666", "666",     "666"]
    ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have situation, where running a query that filters by an indexed column in
We have situation where say we have four engineers that are working on software
Possible Duplicate: What is my script src URL? I have situation: <script type=text/javascript src=http://server/some.js>
I have situation like this: I have commited files a,b,c,d.Now i found that by
I have this situation: To edit the klient, UpdateView is used: url(r'^klient_change/(?P<pk>\d+)/$', KlientUpdateView.as_view(), name='url_klient_change'),
Current situation: Have a timesheet that allows the user to enter their leave, TOIL,
I have this situation where I declare inside my main class a function that
I have a situation where I need to ensure that there is only one
I have situation where I have a variable being used in some arithmetic (mostly
I am coding application with SVG and pure JavaScript. I have situation where one

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.