c# - 从 Web 服务返回到 Android TextView 的数组打印 anyTpe{String 而不是仅打印值

标签 c# android web-services ksoap2

我想将从 web 服务返回的数组打印到 android TextView 。但是当它打印数组时,它会将结果显示为“anyType{string=Shean;string=Ya;string=Hey;},而不是将其打印为 Shean Ya Hey.. 知道我做错了什么吗?

android代码如下:

package com.example.fp1_webservicedropdown;

    import android.app.Activity;
    import android.os.Bundle;
    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 result;
        Spinner spinnerC;

        @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            spinnerC = (Spinner) findViewById(R.id.spinner1);
            result = (TextView) findViewById(R.id.textView2);

            final String NAMESPACE = "http://sample.com/";
            final String METHOD_NAME = "GetCustomerList";
            final String SOAP_ACTION = "http://sample.com/GetCustomerList";
            final String URL = "http://10.113.28.241/HelloWorldNew/Service1.asmx";

            SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
            // Request.addProperty("a", "32");
            // Request.addProperty("b", "12");

            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;
                int intPropertyCount = response.getPropertyCount();

                for (int i = 0; i < intPropertyCount; i++) {
                    SoapObject responseChild = (SoapObject) response.getProperty(i);
                    result.setText(responseChild.toString());
                    // You can add all strings in a list and give
                    // ArrayAdapter<String> for Spinner
                }

                /*
                 * result.setText("The web service returned " +
                 * resultString.toString());
                 */
                // ---------- result To Spinner Code -----------------------//
                /*
                 * String[] toSpinner = new String[] { resultString.toString() };
                 * ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 * android.R.layout.simple_spinner_item, toSpinner);
                 * adapter.setDropDownViewResource
                 * (android.R.layout.simple_spinner_dropdown_item);
                 * spinnerC.setAdapter(adapter);
                 */
                // ---------- result To Spinner Code ends here -----------------//

            } catch (Exception e) {

                e.printStackTrace();

            }
        }
    }

网页方法如下:

 [WebMethod]
        public string[] GetCustomerList()
        {
            //substitute code to actually populate the array with the dataset data
            string[] personIds = { "Shean", "Ya", "Hey" };
            return personIds;
        }

最佳答案

这个有用吗?

for (int i = 0; i < intPropertyCount; i++) {
    SoapObject responseChild = (SoapObject) response.getProperty(i);
    for (int j = 0; j < lengthOfResponseChild; j++)
        result[j].setText(responseChild[j].toString());
    }
}

这只是粗略的代码。您可能需要清理以获得正确的函数和变量。

关于c# - 从 Web 服务返回到 Android TextView 的数组打印 anyTpe{String 而不是仅打印值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13818054/

相关文章:

android - 无法设置 float 操作按钮的渐变背景

c# - WCF和错误处理,最佳实践

android - 在 URL.openStream() Android 上设置超时

java - 如何连接到 SOAP/WSDL Web 服务?

java.lang.NoClassDefFoundError : Could not initialize class weblogic. wsee.jaxws.spi.WLSProvider

c# - 如何避免 EF 生成的查询中的 N+1

c# - 在现有框架中调整/包装 MediatR 通知

c# - 日志解析器 - 通过 MSUtill 查询并通过 C# 代码读取记录

c# - 如何使用 BinaryWriter 编写列表?

java - addValueEventListener(new ValueEventListener() 不读取数据