开发者

Android Question-i have a soap web service and want to use json parsing

i am new for json parsing my question is how can json parsing can be done i have logi开发者_开发百科n page and wanted to move to home page how it can be done please guide me step by step and if any code is there that wil


SOAP uses XML as a data format and JSON and XML are different formats. So you have to make your mind which one you'd like to use.


//web method
public static String UserLogin(String userName, String password) {
        String METHOD_NAME = "Sign_Me_In_Thru_MobileApp";
        String SOAP_ACTION = "http://tempuri.org/Sign_Me_In_Thru_MobileApp";
        try {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("user", userName);
            request.addProperty("password", password);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            new MarshalBase64().register(envelope); // serialization
            envelope.dotNet = true;
            Log.d("test", "URL = " + URL);
            Log.d("test", "request= " + request.toString());
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

            if (response != null) {
                res = response.toString();
            } else {
                res = "0";
            }

            Log.d("test", "getService_Login response = " + res);
        } catch (Exception e) {
            Log.d("test", "Error - " + e.toString());
            res = "Error";
        }
        return res;
    }
//asynctask here for parsing json

private class CreateUserLogin extends AsyncTask<Void, Void, Void> {

        String response = null;

        @Override
        protected void onPreExecute() {
            pDialog = new ProgressDialog(UserLogin.this);
            pDialog.setIndeterminate(false);
            pDialog.setMessage("");
            pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub

            response = WebCall.UserLogin(Input_UserName.getText().toString(),
                    Input_Password.getText().toString());
            // Response=WebCall.GetCommisiioning("8087681884", 5);
            // Response=WebCall.GetComplaintsService(25, 1);

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            Utils.ShowLogd(response);


            try {
                JSONArray ja = new JSONArray(response);

                for (int i = 0; i < ja.length(); i++) {
                    JSONObject job = ja.getJSONObject(i);

                    userID=job.getInt("id");
                    DataSource.SaveDataToPre_Int(getApplicationContext(), AppConstant.USER_DETAILS, AppConstant.User_ID, job.getInt("id"));
                    Intent intent = new Intent(getApplicationContext(),
                            Search_Service.class);
                    startActivity(intent);
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }





            pDialog.dismiss();
        }

    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜