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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:11:19+00:00 2026-06-09T23:11:19+00:00

I have a problem sending JSON Array to Servle t from Android. But I

  • 0

I have a problem sending JSON Array to Servlet from Android. But I am able to send the same JSON Array via the Browser. I have spent many hours trying to solve this problem, but can’t find a solution.

URL = "http://192.168.*.*:8080/Test/TestServlet?q=add&array="

And I have add JSON Array at the end:

[{"amount":"3","test":"test",...}]

GlassFish server error:

org.json.JSONException: A JSONArray text must start with '[' at character 0 of 

Waiting for reply, thank you.

Servlet:

protected void doPost(HttpServletRequest request,HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json");
    PrintWriter out = response.getWriter();
    String req = request.getParameter("q");


    try 
    {
        Class.forName("com.mysql.jdbc.Driver");
        System.out.println("Driver found");

        dbConnect = DriverManager.getConnection("jdbc:mysql://localhost/***",  
                                                       "root", "***");
        dbStatement = dbConnect.createStatement();

        if (req.equals("add")) {
            String json_array = request.getParameter("array");

            String query = null;
            org.json.JSONArray jArray = new org.json.JSONArray(json_array);
            for (int i = 0; i < jArray.length(); i++)
            {
              org.json.JSONObject obj = jArray.getJSONObject(i);
              query = 
                 "INSERT INTO *** (...) VALUES(" + obj.getInt("***") + ",'" +  
                 obj.getString("***") + "','" + obj.getString("***") + "','" +  
                 obj.getString("***") + "'," + obj.getDouble("***") + "," +  
                 obj.getDouble("***") + "," + obj.getDouble("***") + ",'" +  
                 obj.getString("***") + "','"+obj.getString("***")+"','','"+  
                 obj.getString("***") + "')";
            }

            dbStatement.executeUpdate(query);
    ...

Android

protected void sendJson(JSONArray json) 
{
      HttpClient client = new DefaultHttpClient();
      HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
      HttpResponse response;
      try
      {
        HttpPost post = new HttpPost(URL);
        StringEntity se = new StringEntity(json.toString());  
        Log.i("JSON before sending", json.toString());

        se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        post.setEntity(se);
        response = client.execute(post);

        /*Checking response */
        if(response!=null)
        {
          InputStream in = response.getEntity().getContent();   
          //Get the data in the entity
        }
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
 }
  • 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-09T23:11:21+00:00Added an answer on June 9, 2026 at 11:11 pm

    On browser you are trying with GET method whereas in your code you are using POST method. Try using the GET method in your code. Following is a example of GET method to be used with HttpClient

    GetMethod get = new GetMethod("http://www.example.com/page");
    method.setQueryString(new NameValuePair[] {
        new NameValuePair("q", "add"),
      new NameValuePair("array", "[{"amount":"3","test":"test"}]"),
    });
    

    then use client.execute(post); to call the server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with sending string via game center. I am able to
Hi I have a problem in sending data from php to pdf. I think
I have a problem when trying to send a POST request. The sending method
I have a little problem, I'm making project and I'm sending data from client
I have a problem with sending a JSON to a Server with REST API.
Hi i have a problem i'm not able to solve. In my Android\java application
I have the following problem. A web service is sending a JSON POST request
From my view I am sending via $.ajax a JSON object to my controller
I have a problem sending POST request with VB6. The code below works properly
I have a problem with sending POST http request. It stops on (HttpWebResponse)request.GetResponse() and

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.