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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:09:11+00:00 2026-05-26T21:09:11+00:00

I have an ArrayList of type String that contain certain values. I want to

  • 0

I have an ArrayList of type “String” that contain certain values. I want to send this ArrayList to a remote database using a web service. I plan to use JSON to insert the same but I am facing certain difficulties and want to know to go about it.

Here is my code at present:

I have my ArrayList defined like this. It’s purpose is to store checkbox values

      ArrayList<String> items2 = new ArrayList<String>();

            for (int i = 0; i < arr2.length; i++) 
            {
                if (checkedabsent.get(i)) 
                {
                    items2.add(arr2[i]); //arr2 is a String array containing all values
                    System.out.println(items2);
                }
            }

            Log.d("", "items:");
            for (String string : items2)
            {
                Log.d("", string);
                System.out.println(items2);
            }

Here is what I am finding difficult !! The JSON code

   HttpPost httppost = new HttpPost("http://10.0.2.2/enterdata/Service1.asmx");
   HttpClient client = new DefaultHttpClient(httpParams);

    try
            {
            String result;
            JSONObject obj = new JSONObject();
           // how do I put the array list over here ??           

            int TIMEOUT_MILLISEC = 10000;  // = 10 seconds
            HttpParams httpParams = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
            HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);

            httppost.setHeader("Content-Type", "application/json");
            httppost.setHeader("Accept","application/json");

            // Execute HTTP Post Request
            HttpResponse httpResponse = client.execute(httppost);
            HttpEntity httpEntity = httpResponse.getEntity();


            if (httpEntity != null) 
            {
                InputStream is = httpEntity.getContent();
                result = is.toString();
                Log.i("Result is ", "Result: " + result);
                if(result.equalsIgnoreCase("success"))
                {
                    startActivity(new Intent(Mark.this,nextscreen.class));
                }
            }

            }
  • 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-05-26T21:09:11+00:00Added an answer on May 26, 2026 at 9:09 pm

    To convert to a JSON array, you’d use the following

    ArrayList<String> list = new ArrayList<String>();
    list.add("Item 1");
    list.add("Item 2");
    JSONArray jsArray = new JSONArray(list);
    

    Then pass jsArray like described here.

    Sorry if I’ve misunderstood your question.

    Update, so:

      ArrayList<String> items2 = new ArrayList<String>();
    
            for (int i = 0; i < arr2.length; i++) 
            {
                if (checkedabsent.get(i)) 
                {
                    items2.add(arr2[i]); //arr2 is a String array containing all values
                    System.out.println(items2);
                }
            }
    
            Log.d("", "items:");
            for (String string : items2)
            {
                Log.d("", string);
                System.out.println(items2);
            }
    
            HttpPost httppost = new HttpPost("http://10.0.2.2/enterdata/Service1.asmx");
            HttpClient client = new DefaultHttpClient(httpParams);
    
            try
            {
                String result;
                //JSONObject obj = new JSONObject();
                JSONArray jsArray = new JSONArray(items2);
    
                int TIMEOUT_MILLISEC = 10000;  // = 10 seconds
                HttpParams httpParams = new BasicHttpParams();
    
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an arraylist that gets different type of values in it, 1st value->
I have java API which return this type: ArrayList[ArrayList[String]] = Foo.someJavaMethod() In scala program,
I have an ArrayList<String> that I'd like to return a copy of. ArrayList has
I have an ArrayList<String> , and I want to remove repeated strings from it.
I have an ArrayList that I want to use to hold RaceCar objects that
I have an arraylist that holds a subset of names found in my database.
I have a string serialization utility that takes a variable of (almost) any type
I am currently developing an Android app that is using a remote MySQL database
I have a hashmap of the type HashMap<Long, ArrayList<String>> . I need to override
Error: Cannot convert type 'string' to 'object[*,*]' That's the error I have been getting.

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.