aspx Web サービスから返された配列を Android TextView に出力しようとしています。実際には、次の Android C# aspx コードを使用して、テキスト ビューでデータを読み取ることができます。しかし、問題は、出力を次の形式で印刷することです。
anyType{string="Shean";string="Ya";string="Hey";}
Shean Ya & Heyではなく
そこで、次のように配列を読み取ることにしました。
for (int i = 0; i < intPropertyCount; i++) {
SoapObject responseChild = (SoapObject) response.getProperty(i);
int lengthOfResponseChild = responseChild.getPropertyCount();
for (int j = 0; j < lengthOfResponseChild; j++) {
//Error Highlight is as responseChild[j]
result.setText(responseChild[j].toString());
}
//Used this line and prints output on a textView as anyType{string="Shean";string="Ya";string="Hey";}
//result.setText(responseChild.toString());
}
ただし、強調表示されているエラーがあります
result.setText(responseChild[j].toString());
どの州The type of the expression must be an array type but it resolved to SoapObject
私の完全な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://myLocalIP/HelloWorldNew/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;
int intPropertyCount = response.getPropertyCount();
for (int i = 0; i < intPropertyCount; i++) {
SoapObject responseChild = (SoapObject) response.getProperty(i);
int lengthOfResponseChild = responseChild.getPropertyCount();
for (int j = 0; j < lengthOfResponseChild; j++) {
//Error Highlight is as responseChild[j]
result.setText(responseChild[j].toString());
}
//Used this line and prints output on a textView as anyType{string="Shean";string="Ya";string="Hey";}
//result.setText(responseChild.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
私の完全な ASP Web メソッド コードは次のとおりです。
[WebMethod]
public string[] GetCustomerList()
{
//substitute code to actually populate the array with the dataset data
string[] personIds = { "Shean", "Ya", "Hey" };
return personIds;
}