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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:56:22+00:00 2026-06-04T20:56:22+00:00

My server returns a JSON object via the body of an HTTP POST response,

  • 0

My server returns a JSON object via the body of an HTTP POST response, but I get the this error when my app tries to convert the string into a JSONObject:

06-02 09:05:34.380: E/JSONException_MyAppService(19913): org.json.JSONException: Value {"VALS":{"VAL1":"hello","VAL2":"hello2","VAL3":"hello3"}} of type java.lang.String cannot be converted to JSONObject

It looks like my server is returning a acceptable JSON encoded string, but it just won’t convert to a JSONObject. I even changed the content-type of the server’s response header to “application/json”. Please help me fix this, I’ve been trying all day.

EDIT- I use the following code:

try {
    ResponseHandler<String> responseHandler=new BasicResponseHandler();
    String responseBody = client.execute(post, responseHandler);
    JSONObject response=new JSONObject(responseBody);
} catch (ClientProtocolException e) {
    e.printStackTrace();
    Log.e("ClientProtocol_"+TAG,""+e);
} catch (ClientProtocolException e) {
    e.printStackTrace();
    Log.e("IO_"+TAG,""+e);
} catch (ClientProtocolException e) {
    e.printStackTrace();
    Log.e("JSONException_"+TAG,""+e);
}

I also tried imran khan’s suggestion:

try {
    HttpResponse response = client.execute(post);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        String retSrc = EntityUtils.toString(entity); 
        // parsing JSON
        JSONObject result = new JSONObject(retSrc); //Convert String to JSON Object
        JSONArray tokenList = result.getJSONArray("VALS");

        JSONObject oj = tokenList.getJSONObject(0);
        String token = oj.getString("VAL1"); 
        String token1 = oj.getString("VAL2");
        String token11 = oj.getString("VAL3");  
    }
} catch (ClientProtocolException e) {
    e.printStackTrace();
    Log.e("ClientProtocol_"+TAG,""+e);
} catch (ClientProtocolException e) {
    e.printStackTrace();
    Log.e("IO_"+TAG,""+e);
} catch (ClientProtocolException e) {
    e.printStackTrace();
    Log.e("JSONException_"+TAG,""+e);
}

:'( :'(

  • 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-04T20:56:23+00:00Added an answer on June 4, 2026 at 8:56 pm

    How are you doing it? It should work with:

    JSONObject object = new JSONObject (yourString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a response to a POST, the server returns very simple JSON object that
Server returns json object shown as below: its around 51 objects [{location:Location1,email:sriharsha@yahoo.com,phone:123456},{location:Location2,email:sriharsha.mandya@gmail.com,phone:123456789}, . .
I'm using jquery ajax. The server returns a JSON object and I am fetching
Via jquery, I ajax/POST this json {indices:[1,2,6]}: to a symfony2 action. Right now I
I have a very basic Rest Server which returns JSON object. I tested it
I have my php coded page on one server that returns a json result.
I'm have an action /json that returns json from the server. Unfortunately in IE,
I'm trying to return json content read from MySQL server. This is supposed to
I am posting to the server using jquery ajax using $.post. After server returns
A simple get request made to url on my server which returns HTML of

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.