0

我有一个 java web 服务,我想与一个使用 ksoap 的 android 客户端一起使用。我的网络服务给出了一个如下所示的答案:

java.util.List : "[mobilerestaurantbooking.RMenu@66eb63f8,
mobilerestaurantbooking.RMenu@67f06391,
mobilerestaurantbooking.RMenu@5718f9e6,
mobilerestaurantbooking.RMenu@28be97b6,
mobilerestaurantbooking.RMenu@78da429f]"

这类似于 id, name , category,.... 并将其传递给我的应用程序,但输出类似于 anyType{}

这是我在android中的代码

        try {
            aht.call(SOAP_ACTION, soapEnvelope);
            SoapObject response = (SoapObject)soapEnvelope.bodyIn;
            List<String> categories = new ArrayList<String>();
            int count = response.getPropertyCount();

            for(int i = 0; i < count; i++) {
                if(response.getProperty(i) != null)
                    categories.add(response.getProperty(i).toString());
            }

谁知道我该怎么办?

4

3 回答 3

1
public class KSOAP extends Activity 
{
    ListView list;
    ArrayList<String> arraylist = new ArrayList<String>();
    ArrayAdapter<String>  arrayadapter;

    Button btn;
    TextView tv,tv2,tv3; 
    EditText no1,no2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{ 
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

tv=(TextView)findViewById(R.id.textView1);
tv2=(TextView)findViewById(R.id.textView2);
//tv3=(TextView)findViewById(R.id.textView3);

list=(ListView)findViewById(R.id.listView1);

no1=(EditText)findViewById(R.id.editText1);
no2=(EditText)findViewById(R.id.editText2);

btn =(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub


        String NAMESPACE = "http://tempuri.org/" ;    
        //"http://vladozver.org/";
        String METHOD_NAME = "GetStringList"; //"GetSumOfTwoIntsList";//
        String SOAP_ACTION = "http://tempuri.org/GetStringList";  
        //"http://vladozver.org/GetSumOfTwoInts";
        String URL = "http://192.168.0.203/recharge_service/service.asmx";
        //"http://192.168.0.203/Recharge_Service/Service.asmx";


        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

//      PropertyInfo pi = new PropertyInfo();
//      pi.setName("Operand1");
//      pi.setValue(Integer.parseInt(no1.getText().toString()));
//      pi.setType(int.class);
//      Request.addProperty(pi);
//
//      PropertyInfo pi2 = new PropertyInfo();
//      pi2.setName("Operand2");
//      pi2.setValue(Integer.parseInt(no2.getText().toString()));
//      pi2.setType(int.class);
//      Request.addProperty(pi2);


        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(Request);
        try
        {
        AndroidHttpTransport transp = new AndroidHttpTransport(URL);
        transp.call(SOAP_ACTION, envelope);

        SoapObject obj1 = (SoapObject) envelope.bodyIn;

        SoapObject obj2 =(SoapObject) obj1.getProperty(0);


        for (int i = 0; i< obj2.getPropertyCount(); i++) 
            { 
                // int id1 = Integer.parseInt(obj2.getProperty(0).toString());
               String id1=obj2.getProperty(0).toString();

               if(id1 != "")
               { 
                 arraylist.add( id1);   

               }
                /* tv3.setText(id3);*/
            }


        }
        catch(Exception e)
        { tv.setText(e.toString());
        e.printStackTrace();
        }

        //tv.setText(""+ count);



               list.setAdapter(arrayadapter);
    }
});

        arrayadapter = new ArrayAdapter<String>( this, 
        android.R.layout.simple_list_item_1, arraylist );
       list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub

        }
    });

}


}
于 2013-04-03T08:42:06.997 回答
0

我也喜欢它,但我在菜单类中没有任何记录。

SoapObject result = (SoapObject) soapEnvelope.bodyIn;


Menu[] menus = new Menu[result.getPropertyCount()];

for (int i = 0; i < menus.length; i++) { 
   SoapObject so = (SoapObject) result.getProperty(0); 
   Menu s = new Menu(); 
   s.setID(Integer.parseInt(so.getProperty(0).toString())); 
   s.setName(so.getProperty(1).toString()); 
   s.setPrice(Double.parseDouble(so.getProperty(2).toString())); 
   s.setCategory(so.getProperty(3).toString()); 
   menus[i] = s; 
 }
于 2013-01-05T08:50:21.717 回答
0
SoapObject result = (SoapObject) soapEnvelope.bodyIn;
Menu[] menus = new Menu[result.getPropertyCount()];
for (int i = 0; i < menus.length; i++) {
SoapObject so = (SoapObject) result.getProperty(i);
    ID = so.getProperty(0).toString();
    Name = so.getProperty(1).toString();
    price = so.getProperty(2).toString();
    Catagory = so.getProperty(3).toString();
}

在一个对象中得到结果后:

SoapPrimitive so = (SoapPrimitive) so.getProperty(1);
firstlist[i] = so.getPropertyAsString(0).toString();
于 2013-02-28T12:06:19.597 回答