gpt4 book ai didi

java - Android 中的对象到字符串数组

转载 作者:行者123 更新时间:2023-12-01 15:54:50 26 4
gpt4 key购买 nike

如何将数据存储在对象的数组中?该对象包含从 Web 服务检索的数据。

这是我的代码:

package projects.ksoap2sample;

import android.app.Activity;
import android.os.Bundle;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.widget.Button;
import android.view.View.OnClickListener;
//import com.example.android.R;

import android.app.*;
import android.os.*;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class ksoap2sample extends Activity { /** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static final String METHOD_NAME = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://173.161.245.235/test/Service.asmx";
TextView tv;
String[] results;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

tv=(TextView)findViewById(R.id.TextView01);
call();
}
/* try
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//request.addProperty("prop1", "myprop");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object result = (Object)envelope.getResponse();
String[] results = (String[]) result;
tv.setText( ""+results[0]);
}
catch (Exception e)
{
tv.setText(e.getMessage());
}
} */


public void call()
{
try {

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

// request.addProperty("passonString", "Rajapandian");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);

Object result = (Object)envelope.getResponse();
String str1=result.toString();

System.out.println("length="+result.toString().length());


for(int i=0;i<str1.length();i++)
{

int j=str1.indexOf(";");
String str=str1.substring(0, j);
results[i]=str;
System.out.println("Result="+results[i]);

/*results[i]=result.toString();
if(results[i]==";")
{
results[i].i
}*/
//String[] results = (String[]) result;
//result.toString().endsWith(";");

//results[i]=result.toString().endsWith(";");


// String[] results = (String[]) result;
tv.setText( ""+results[i]);
}

tv.setText(result.toString());
/*SoapObject result=(SoapObject)envelope.getResponse();

//to get the data
String resultData=result.getAttribute(1).toString();
// 0 is the first object of data
System.out.println("Result"+resultData);
tv.setText(resultData.toString());*/
} catch (Exception e) {
tv.setText(e.getMessage());
}
}


}

这是我的代码,但 results[i] 存储空值。我该怎么办?

最佳答案

鉴于“从 Web 服务检索的数据”保存在名为 Foo 的类的实例中,该数组将是 Foo[] 局部变量或数据成员,正如您在一些 Java documentation 中看到的那样.

关于java - Android 中的对象到字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5282739/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com