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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:39:43+00:00 2026-06-11T04:39:43+00:00

I’m creating an app that fetches back a Json response from a webservice. The

  • 0

I’m creating an app that fetches back a Json response from a webservice. The app is in 2 files a webclient and a webserviceActivity. The client is coming back ok i think as logcat is printing HTTP/1.1 200 OK. After that there seems to be a JSONException. It may have something to do with the format of the 2nd parameter passed in the url as it’s a date. I tried passing in a string but to no avail. the way i have done it here is to create a date object from sql.Date(yyyy mm dd) and pass that in. In this way i get a bit back from the server before the JSONException

Here are the files. Thanks in advance.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.util.Log;

public class WebClient {

    private static final String TAG = WebClient.class.getSimpleName();



    private static String convertStreamToString(InputStream is) {
        /*
         * To convert the InputStream to String we use the
         * BufferedReader.readLine() method. We iterate until the BufferedReader
         * return null which means there's no more data to read. Each line will
         * appended to a StringBuilder and returned as String.
         */
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }

    /*
     * This is a test function which will connects to a given rest service and
     * prints it's response to Android Log with labels "Praeda".
     */
    public JSONObject connect(String url) {

        JSONObject json = null;
        HttpClient httpclient = new DefaultHttpClient();

        // Prepare a request object
        HttpGet httpget = new HttpGet(url);

        // Execute the request
        HttpResponse response;
        try {
            response = httpclient.execute(httpget);
            // Examine the response status
            Log.i(TAG, response.getStatusLine().toString());

            // Get hold of the response entity
            HttpEntity entity = response.getEntity();
            // If the response does not enclose an entity, there is no need
            // to worry about connection release

            if (entity != null) {

                // A Simple JSON Response Read
                InputStream instream = entity.getContent();
                String result = convertStreamToString(instream);
                Log.i(TAG, result);

                // A Simple JSONObject Creation
                json = new JSONObject(result);



                // Closing the input stream will trigger connection release
                instream.close();

            }

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         return json;

    }
}

.

import java.sql.Date;

import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class WebserviceActivity extends Activity {

    private static final String TAG = WebserviceActivity.class.getSimpleName();
    TextView tv = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        tv = (TextView) findViewById(R.id.textviewwebserviceresponse);

        WebClient rc = new WebClient();


        @SuppressWarnings("deprecation")
         Date d = new Date(2012, 9, 3);
        JSONObject jObj = rc
                .connect("http://212.169.27.217:84/rotaservice.asmx/GetRota?CarerID=36&RotaDate="+d);
         Log.e(TAG, "json obj = " + jObj.toString());
        tv.setText(jObj.toString());

    }// end of onCreate

}// end of class

.

09-03 19:52:00.490: I/global(21931): In close() at SocketHttpClientConnection
09-03 19:52:00.490: I/global(21931): call createSocket() return a new socket.
09-03 19:52:03.610: I/WebClient(21931): HTTP/1.1 200 OK
09-03 19:52:03.610: I/WebClient(21931): <?xml version="1.0" encoding="utf-8"?>
09-03 19:52:03.610: I/WebClient(21931): <string xmlns="http://tempuri.org/">{"0":{"StartDate":"","EndDate":"","Duration":"0","CallStatusID":"0","CallStatusName":"","ClientSurname":"","ClientForename":"","NeedName":"Out of range","CarerAwayReason":"","CallID":"","DoubleUpCallID":""}}</string>
09-03 19:52:03.620: W/System.err(21931): org.json.JSONException: Value <?xml of type java.lang.String cannot be converted to JSONObject
09-03 19:52:03.620: W/System.err(21931):    at org.json.JSON.typeMismatch(JSON.java:111)
09-03 19:52:03.620: W/System.err(21931):    at org.json.JSONObject.<init>(JSONObject.java:158)
09-03 19:52:03.620: W/System.err(21931):    at org.json.JSONObject.<init>(JSONObject.java:171)
09-03 19:52:03.620: W/System.err(21931):    at com.carefreegroup.WebClient.connect(WebClient.java:87)
09-03 19:52:03.620: W/System.err(21931):    at com.carefreegroup.WebserviceActivity.onCreate(WebserviceActivity.java:31)
09-03 19:52:03.620: W/System.err(21931):    at android.app.Activity.performCreate(Activity.java:4543)
09-03 19:52:03.620: W/System.err(21931):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
09-03 19:52:03.620: W/System.err(21931):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
09-03 19:52:03.620: W/System.err(21931):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2260)
09-03 19:52:03.620: W/System.err(21931):    at android.app.ActivityThread.access$600(ActivityThread.java:139)
09-03 19:52:03.620: W/System.err(21931):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
09-03 19:52:03.620: W/System.err(21931):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 19:52:03.620: W/System.err(21931):    at android.os.Looper.loop(Looper.java:156)
09-03 19:52:03.620: W/System.err(21931):    at android.app.ActivityThread.main(ActivityThread.java:5045)
09-03 19:52:03.620: W/System.err(21931):    at java.lang.reflect.Method.invokeNative(Native Method)
09-03 19:52:03.630: W/System.err(21931):    at java.lang.reflect.Method.invoke(Method.java:511)
09-03 19:52:03.630: W/System.err(21931):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-03 19:52:03.630: W/System.err(21931):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-03 19:52:03.630: W/System.err(21931):    at dalvik.system.NativeStart.main(Native Method)
09-03 19:52:03.630: D/AndroidRuntime(21931): Shutting down VM
  • 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-11T04:39:45+00:00Added an answer on June 11, 2026 at 4:39 am

    The service returns XML with JSON in the string tag, you’ll have to parse the XML to get the JSON it contains.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.