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

  • Home
  • SEARCH
  • 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 8819087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:15:59+00:00 2026-06-14T05:15:59+00:00

After doing considerable research I haven’t been able to find someone using AsyncTask to

  • 0

After doing considerable research I haven’t been able to find someone using AsyncTask to HttpPost a JSONObject by passing the JSONObject in and then retrieving server-side. I am populating a JSONObject Through multiple HashMaps.

When I pass the JSONObject to AsyncTask I am getting what looks like a JSONObject reference, which from that, I am unsure of how to parse properly, PHP server-side.


JSONObject builder method and AsyncTask caller:

HashMap<Integer, HashMap<String, String>> finalHash;
HashMap<String, String> semiFinalHash;
private void completeSurvey() throws JSONException {

    finalHash = new HashMap<Integer, HashMap<String, String>>();
    semiFinalHash = new HashMap<String, String>();

    JSONArray jArray = new JSONArray();
    JSONObject joMap = new JSONObject();
    for (int indexInt = 0; indexInt <= lightingMap.size(); indexInt++) {
        if (lightingMap.containsKey(indexInt) && !placeholderHashMap.containsKey(indexInt)) {
            int checkId = indexInt;
            placeholderHashMap.put(checkId, "null");
        }
    }

    Log.i("", "" + placeholderHashMap.toString());
    for (int finalOutPut = 0; finalOutPut < lightingMap.size(); finalOutPut++) {
        JSONObject jo = new JSONObject();
        try {
            int id = finalOutPut + 1;
            jo.put("id", id);
            jo.put("SurveyPhoto", placeholderHashMap.get(id));
            jo.put("Lighting", lightingMap.get(id));
            jo.put("Notes", signSpecNotesMap.get(id));
            jo.put("AdditionalService", chkBxMap.get(id));
            //jo.put("Coordinates", latLngMap.get(id));
            jArray.put(jo);

        } catch (Exception e) {
            Log.e("", "" + e.getMessage());
        }
    }
    joMap.put(businessName, jArray);
    Log.i("JSONObject", joMap.toString());
    new CompleteSurveyAsync().execute(joMap);
}

AsyncTask Class:

class CompleteSurveyAsync extends AsyncTask<JSONObject, Void, String> {

    public ProgressDialog progressDialog = new ProgressDialog(Main.this);

    protected void onPreExecute() {
        progressDialog.setMessage("Submitting Data to Server...");
        progressDialog.show();
        progressDialog.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface diaInterface) {
                CompleteSurveyAsync.this.cancel(true);
                diaInterface.dismiss();
            }
        });
    }

    String inString, parameterPass;
    JSONObject jobject;
    @Override
    protected String doInBackground(JSONObject... jObject) {

        parameterPass = jObject.toString();
        Log.i("doInBackground", parameterPass);
        String url_select = "http://www.somewebsite.com/db/completedSurvey.php";
        HttpResponse response;
        try {

            HttpPost httpPost = new HttpPost(url_select);
            HttpClient httpClient = new DefaultHttpClient();

            httpPost.setEntity(new ByteArrayEntity(jObject.toString().getBytes("UTF8")));
            httpPost.setHeader("Accept", "application/json");
            httpPost.setHeader("Content-type", "application/json");
            response = (HttpResponse) httpClient.execute(httpPost);

            HttpEntity entity = response.getEntity();

            if(entity != null) {
                InputStream in = response.getEntity().getContent();
                inString = in.toString();
                Log.i("InputStream", "" + in.toString());
            }

        } catch (UnsupportedEncodingException e1) {
            Log.e("UnsupportedEncodingException", e1.toString());
            e1.printStackTrace();
        } catch (ClientProtocolException e2) {
            Log.e("ClientProtocolException", e2.toString());
            e2.printStackTrace();
        } catch (IllegalStateException e3) {
            Log.e("IllegalStateException", e3.toString());
            e3.printStackTrace();
        } catch (IOException e4) {
            Log.e("IOException", e4.toString());
            e4.printStackTrace();
        }
        return parameterPass;
    }

    protected void onPostExecute(String s) {
        this.progressDialog.dismiss();
        Log.i("onPostExecute", s);
        Toast.makeText(Main.this, s, Toast.LENGTH_LONG).show();
    }

}

This gives me a LogCat output of:

11-13 09:52:45.606: I/JSONObject(2601): {"SOME COMPANY":[{"Notes":"null","SurveyPhoto":"[B@427a1fa8","id":1,"Lighting":1,"AdditionalService":0},{"Notes":"null","SurveyPhoto":"null","id":2,"Lighting":0,"AdditionalService":0},{"Notes":"null","SurveyPhoto":"null","id":3,"Lighting":1,"AdditionalService":0},{"Notes":"null","SurveyPhoto":"null","id":4,"Lighting":1,"AdditionalService":0}]}
11-13 09:52:45.626: I/doInBackground(2601): [Lorg.json.JSONObject;@416ad478
11-13 09:52:45.786: I/InputStream(2601): org.apache.http.conn.EofSensorInputStream@416c51d0
11-13 09:52:45.816: I/onPostExecute(2601): [Lorg.json.JSONObject;@416ad478

I validated the JSON, building it works fine but when passing through AsyncTask I start to get [Lorg.json.JSONObject;@4158c990, is this an Object reference? If so, how can I parse this PHP server side?

My current PHP is set to only write to a file:

$json = file_get_contents('php://input');
$jsonObj = json_decode($json, true);

$jsonFile = "json.txt";
$fh = fopen($jsonFile, 'a');

fwrite($fh, $json);
fwrite($fh, "\n");
fwrite($fh, $jsonObj);
fwrite($fh, "\n");

fclose($fh);

Output (json.txt):

[Lorg.json.JSONObject;@416ad478
  • 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-14T05:16:00+00:00Added an answer on June 14, 2026 at 5:16 am

    JSONObject... jObject means that jObject is not JSONObject … it is an varargs/array

    try

    if(jObject.length > 0)
    {
      final JSONObject realjObject = jObject[0];
      //rest of code goes here and instead of jObject we are using realjObject
    }
    

    EDIT:
    instead:

    httpPost.setEntity(new ByteArrayEntity(jObject.toString().getBytes("UTF8")));
    

    use(just for clean code :)):

    httpPost.setEntity(new StringEntity(jObject.toString(), "UTF8"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After doing tons of research and nor being able to find a solution to
After doing some research on the subject, I've been experimenting a lot with patterns
After doing some initial research into using Appfabric for caching, my understanding is that
After doing some research on this issue, I couldn't find any satisfying fix. The
after doing some preliminary searching, I was not able to find much information on
after doing some research i'm still not sure if using mysql with .net desktop
After doing lot of research in Google, I found this program: #include <stdio.h> int
After doing some Core animations using: [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; [self setAffineTransform:CGAffineTransformIdentity]; [UIView
After doing a long search on stackoverflow i didn't find any one talked about
So after doing a lot of research I found base href, and I decided

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.