I want to parse JSON data as a string parameter to the web service.
My class is mentioned below.
@Override
protected String doInBackground(String... params) {
    // TODO Auto-generated method stub
    HttpClient httpclient = new DefaultHttpClient();
    //URL url = new URL("http://192.168.1.44:8080/api/BeVoPOSAPI/checklogin?nodeid=2");
    //Log.d("shankar: ", ip+":"+port+"/"+node);
    //String url = "http://"+ip+":"+port+"/api/BeVoPOSAPI/checklogin?nodeid="+node+"&login=";
    //String url = "http://"+ip+":"+port+"/api/BeVoPOSAPI/checklogin?nodeid="+node+"&login=";
    //String url = "http://192.168.1.60:8081/api/BeVoPOSAPI/checklogin?nodeid=2&login=";
    String url = "http://ipa.azurewebsites.net/pos/savecheck?nodeid=2&checkxml=";
    try {
        // Add your data
        String checkxml = new String(params[0]);
        ;
        url = url.concat(checkxml);
        Log.d("password", checkxml);
        //HttpPost httppost = new HttpPost(url);
        //HttpParams httpParameters = new BasicHttpParams();
        //HttpConnectionParams.setConnectionTimeout(httpParameters, 1000);
        //HttpConnectionParams.setSoTimeout(httpParameters, 1000);
        //HttpClient httpClient = new DefaultHttpClient(httpParameters);
        //HttpContext localContext = new BasicHttpContext();
        HttpPost httpget = new HttpPost(url);
        HttpParams httpParameters = new BasicHttpParams();
        // Set the timeout in milliseconds until a connection is established.
        // The default value is zero, that means the timeout is not used.
        int timeoutConnection = 300;
        HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
        // Set the default socket timeout (SO_TIMEOUT)
        // in milliseconds which is the timeout for waiting for data.
        int timeoutSocket = 500;
        HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
                /*List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
                Log.d("password", password_check);
                nameValuePairs.add(new BasicNameValuePair("login", password_check));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));*/
        // Execute HTTP Post Request
        DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
        httpClient.setParams(httpParameters);
        HttpResponse response = httpclient.execute(httpget);
        Log.d("Status", response.toString());
        int responseCode = response.getStatusLine().getStatusCode();
        String str = Integer.toString(responseCode);
        Log.d("Responce code", str);
        switch (responseCode) {
            case 200:
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    String responseBody = EntityUtils.toString(entity);
                    Log.d("Responce", responseBody.toString());
                    String jsonString = responseBody.toString();
                }
                break;
        }
    } catch (SocketTimeoutException e) {
        error = "SocketTimeoutException";
    } catch (ConnectTimeoutException e) {
        error = "connectionTimeoutException";
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        //Log.d("Error", e.toString());
        error = "ClientProtocolException";
    } catch (IOException e) {
        // TODO Auto-generated catch block
        //Log.d("Error", e.toString());
        error = "IOException";
    }
    return null;
}I parsed the checkxml string from another method.
The checkxml consists of the details below as a string.
   {
    "layoutid": 1,
    "total": "2.95",
    "checkdiscountpercentage": 0,
    "gratuityid": "",
    "status": 141,
    "checkdiscountshiftlevelid": "",
    "checktimeeventid": "",
    "isprintonbill": "",
    "userid": 1,
    "gratuitypercentage": "",
    "checkdiscountreason": "",
    "ordertype": 210,
    "noofcustomer": 1,
    "generatedon": "",
    "istaxexcemt": 0,
    "checkdefinitiontype": "",
    "tableid": 1,
    "customerid": 0,
    "ticket": "new",
    "checkdiscountamount": "0",
    "tablename": 100,
    "checkdiscountistaxadjust": "1",
    "checkdiscounttax": "0",
    "products": [
        {
            "menuitemname": "2",
            "menuitemid": 1,
            "reason": "",
            "discountpercentage": 0,
            "seatid": 1,
            "timeeventid": "",
            "SaleDetailsMenuItem_ID": "2",
            "istaxexcemt": "2",
            "taxamount": "0.2100",
            "discounttax": "0",
            "definitiontype": "",
            "modifiers": [
                {}
            ],
            "discountamount": "0",
            "istaxinclude": "2",
            "seatname": "",
            "shiftlevelid": "2",
            "discountshiftlevelid": "",
            "discountreason": "",
            "status": "2",
            "coursingid": "",
            "qty": 2,
            "ordertype": "",
            "taxpercent": "2",
            "taxids": [
                {
                    "taxpercent": "7",
                    "Amount": "0.21",
                    "taxid": "1"
                }
            ],
            "holdtime": 0,
            "price": 2.95,
            "discountistaxadjust": 1,
            "price2": 3
        }
    ]
}It threw an illegal argument and thread pool exception. Please let me know how to parse this data as a parameter to the above url.










 android
android
