如何将我从aspx web服务接收到的对象中的内容分离到android?

如何将我从aspx web服务接收到的对象中的内容分离到android?,android,asp.net,ksoap2,Android,Asp.net,Ksoap2,我有下面提供的一个aspx Web服务和一个使用该服务的对象的android程序。android程序以如下方式使用对象: anyType{Vehicle=anyType{VehicleID=KL-9876; VehicleType=Nissan; VehicleOwner=Sanjiva;};} 但是现在我想分离对象中的每个内容。我该怎么做 我尝试getAttibute(0)只是为了检查是否可以将车辆ID分离,但不起作用 我的aspx web服务如下所示: using System; usin

我有下面提供的一个aspx Web服务和一个使用该服务的对象的android程序。android程序以如下方式使用对象:

anyType{Vehicle=anyType{VehicleID=KL-9876; VehicleType=Nissan; VehicleOwner=Sanjiva;};}
但是现在我想分离对象中的每个内容。我该怎么做

我尝试getAttibute(0)只是为了检查是否可以将车辆ID分离,但不起作用

我的aspx web服务如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace WebService4
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public List<Vehicle> GetCustomerList()
        {
            Vehicle vehi = simpleCase();
            List<Vehicle> newL = new List<Vehicle> { vehi };
            return newL;

        }

        [WebMethod]
        public Vehicle simpleCase()
        {
            Vehicle obj = new Vehicle();
            obj.VehicleID = "KL-9876";
            obj.VehicleType = "Nissan";
            obj.VehicleOwner = "Sanjiva";
            return obj;
        }
    }

    //someObject.SomeMethod(obj);

    public class Vehicle
    {
        public string VehicleID { get; set; }
        public string VehicleType { get; set; }
        public string VehicleOwner { get; set; }
    }


}
package com.example.objectpass;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import org.ksoap2.*;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.*;

public class MainActivity extends Activity {
    TextView resultA;
    Spinner spinnerC;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        String[] toSpinnerSum;
        toSpinnerSum = new String[9];

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        spinnerC = (Spinner) findViewById(R.id.spinner1);
        resultA = (TextView) findViewById(R.id.textView2);
//
        final String NAMESPACE = "http://tempuri.org/";
        final String METHOD_NAME = "GetCustomerList";
        final String SOAP_ACTION = "http://tempuri.org/GetCustomerList";
        final String URL = "http://192.168.1.104/WebService4/Service1.asmx";

        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(Request);
        AndroidHttpTransport aht = new AndroidHttpTransport(URL);
        //
        try {
            aht.call(SOAP_ACTION, soapEnvelope);
            SoapObject response = (SoapObject) soapEnvelope.bodyIn;
            SoapObject add = (SoapObject) response.getProperty(0);



            String xyz=add.toString();

            resultA.setText(xyz);
            // GetCustomerListResponse{GetCustomerListResult=anyType{Vehicle=null;
            // }; }
            //
        } 
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

您好,我已经尝试使用以下代码段解析您的响应。这不是最终答案,但它将解决您95%的回答

SoapObject result;
    result = (SoapObject) envelope.bodyIn;

    JSONObject tempJsonObject = null;
    String input = result.toString();

    String temp = input.substring(
            input.indexOf("GetCustomerListResult") + 28, input.length() - 2);
    input = null;
    System.out.println("String temp::**" + temp);

    try {

        tempJsonObject = new JSONObject(temp);


        String tempVehicle = tempJsonObject.getString("Vehicle");

        if(tempVehicle!=null){

        String innerTempVehicle = tempJsonObject.toString();

        String temp2= innerTempVehicle.indexOf("anyType") + 28, input.length());
        Log.i("Content of temp2",temp2);

        JSONObject tempJsonObject1 = new JSONObject(temp2);

        String tempVehicleID = tempJsonObject1.getString("VehicleID");
        String tempVehicleType = tempJsonObject1.getString("VehicleType");
        String tempVehicleOwner = tempJsonObject1.getString("VehicleOwner");




        }else{

            Log.i("Vehicle Error","Response Null");

        }

你为什么不使用JSON?@JayantVarshney嘿,我是web开发新手,我需要做什么更改?通过查看并了解如何在android程序中使用它来创建Restful WCF@JayantVarshney嘿,谢谢,但是我不能简单地分离对象,而不是做所有这些吗?