解决方案 »

  1.   

    public static CenterInfo[] getWorkOn(SoapObject obj){
    CenterInfo[] info = null;
    try{
    if(obj.getPropertyCount() > 1){//有中心信息
    int len = obj.getPropertyCount() - 1;
    info = new CenterInfo[len];
    for(int i = 0;i < len;i++){
    SoapObject child = (SoapObject)obj.getProperty(i + 1);
    String idStr = child.getPropertyAsString(0);
    String content = child.getPropertyAsString(1);
    String sender = child.getPropertyAsString(2);
    String typeStr = child.getPropertyAsString(3);
    String uId = child.getPropertyAsString(4);
    String time = child.getPropertyAsString(5);//时间
    long id = Long.parseLong(idStr);
    int type = Integer.parseInt(typeStr);
    info[i] = new CenterInfo(id,content,sender,type,uId,time);
    }
    }
    }catch(Exception e){
    e.printStackTrace();
    }
    return info;
    }
      

  2.   

    请问这个CenterInfo[]是什么啊?新手不懂求指教,还有getPropertyCount()是什么方法?这些都怎么用?
      

  3.   

    可能这个错误大家看不太明白,特贴出代码,求指点:
    MainActivity:public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            searchs=(Button) findViewById(R.id.search);
            results=(TextView) findViewById(R.id.result);
            searchs.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
    String wsdUrl="http://192.168.1.195:88/service1.asmx";
    String method="SelectAll";
    Object result=SOAPUtil.doTransport(wsdUrl, method);
    results.setText(result.toString());

    }
    });
        }
    SoapUtil:
    public static Object doTransport(final String wsdUrl, final String webMethod) {
    String nameSpace = "http://tempuri.org/";
    SoapObject soapObject = new SoapObject(nameSpace, webMethod);
    // soapObject.addProperty(propertyInfo)
    System.out.println();
    SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(
    SoapEnvelope.VER11);
    soapSerializationEnvelope.bodyOut = soapObject;
    soapSerializationEnvelope.dotNet = true;
    soapSerializationEnvelope.setOutputSoapObject(soapObject);
    HttpTransportSE httpTransportSE = new HttpTransportSE(wsdUrl);
    String SOAP_ACTION = "http://tempuri.org/" + webMethod;
    System.out.println(SOAP_ACTION);
    try {
    httpTransportSE.call(SOAP_ACTION, soapSerializationEnvelope);
    System.out.println("调用结束");
    System.out.println(soapSerializationEnvelope.getResponse());
    if (soapSerializationEnvelope.getResponse() != null) {
    SoapObject result = (SoapObject) soapSerializationEnvelope
    .getResponse();
    System.out.println(result);
    return result;
    }
    } catch (IOException e) {
    System.out.println("IOException");
    e.printStackTrace();
    } catch (XmlPullParserException e) {
    e.printStackTrace();
    }
    return null;
    是不是因为我把所有数据都放在一个textview里toString出来的?那我怎么把数据放在listview里并且只显示数据不显示其他的呢?
      

  4.   

    //将SoapObject转换为(CenterInfo)对象数组
    public static CenterInfo[] getWorkOn(SoapObject obj){
    //定义数组
    CenterInfo[] info = null;
    try{
    //如果接收到信息
    if(obj.getPropertyCount() > 1){//有中心信息
    //计算数组的下标的最大值
    int len = obj.getPropertyCount() - 1;
    //初始化对象数组  为数组开辟储存空间
    info = new CenterInfo[len];
    //遍历解析SoapObject
    for(int i = 0;i < len;i++){
    //获取SoapObject对象
    SoapObject child = (SoapObject)obj.getProperty(i + 1);
    //取值
    String idStr = child.getPropertyAsString(0);
    String content = child.getPropertyAsString(1);
    String sender = child.getPropertyAsString(2);
    String typeStr = child.getPropertyAsString(3);
    String uId = child.getPropertyAsString(4);
    String time = child.getPropertyAsString(5);//时间
    long id = Long.parseLong(idStr);
    int type = Integer.parseInt(typeStr);
    //封装成需求对象(CenterInfo),放入资源数组 
    info[i] = new CenterInfo(id,content,sender,type,uId,time);
    }
    }
    }catch(Exception e){
    e.printStackTrace();
    }
    return info;
      

  5.   

    LZ,这个对象是需要解析滴,不可以直接toString......Do you Know ?
      

  6.   

    知道需要解析啊,有人说解析soapObject,有人说解析json,很疑惑都不明白……
    到底解析什么,怎么解析?
      

  7.   

    解析的是你获取的对象啊  你获取的什么就解析什啊? 你获取的SoapObject 难道要转成别的类型再用json解析???
      

  8.   

    结果依然令人窒息!怎么才能使数据一条条对应的显示出来呢?为什么数据前面带着该死的String和anyType啊
      

  9.   

    这要看写http://192.168.1.195:88/service1.asmx这个webservice的怎么定义返回数据的
      

  10.   

    比较好的方法是:两边先定义好返回数据的格式,最好是json格式,可以是google的,也可以是apache的,这样你这边在解析的时候可以用google或者apache提供的工具类解析,很方便。要是直接解析你给的字符串,那就自己写方法处理了。我想不到其它办法
      

  11.   

    感谢大家的热心帮助,最后问题终于解决了:特地写了个解析soapObject的类来完成目标,主要方法:
    public static ArrayList<Map<String, String>> parseSoapObjectToList(
    SoapObject so) {
    ArrayList<Map<String, String>> data = new ArrayList<Map<String, String>>();
    if (so != null) {
    int size = so.getPropertyCount();
    if (size > 0) {
    Map<String, String> map=null;
    for (int i = 0; i < so.getPropertyCount(); i++) {
    int tag = i % 3;
    switch (tag) {
    case 0: {
    map=new HashMap<String, String>();
    map.put("Id", so.getProperty(i).toString());
    }
    break;
    case 1: {
    map.put("Name", so.getProperty(i).toString());
    }
    break;
    case 2: {
    map.put("Status", so.getProperty(i).toString());
    data.add(map);
    }
    break; default:
    break;
    }
    }
    }
    }
    return data; }
      

  12.   

    你的方法很好,请问你是怎样将查询结果显示出来的?是用了Listview吗
      

  13.   

    楼主  我和你遇到了一样的问题 你能发一demo给我吗 [email protected]  好人
      

  14.   

    GetDealerLv2Response{GetDealerLv2Result=anyType{tbDealer=anyType{dealerId=A080502FX00001; dealerName=源丰商店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX00039; dealerName=包媚日用品商店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX00152; dealerName=兴局店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX00154; dealerName=食盐批发部; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX00343; dealerName=何亚元商店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX00701; dealerName=张能考店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX00713; dealerName=兴发店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX00939; dealerName=广信批发部; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX00729; dealerName=兴盛店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX00937; dealerName=素萍商店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX00991; dealerName=红娟商店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX01050; dealerName=谢海荣; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX01067; dealerName=惠民批发部; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX01088; dealerName=沙田诚信商店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX01090; dealerName=贺街联盛商店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080502FX01092; dealerName=祥胤商店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080518FX00364; dealerName=红升商店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080518FX00372; dealerName=业英商店; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A080518FX00404; dealerName=益民批发部; Longitude=0; Latitude=0; Addr=anyType{}; }; tbDealer=anyType{dealerId=A0805...这种类型的怎么解析哇,求解