0

我有一个返回的 SOAP webservice 服务ArrayList<String[]>。当我从客户端调用它时,eclipse 说服务不会返回ArrayList<String[]>但是List<StringArray>

StringArray似乎不是 java 数据类型,我会知道如何将其转换为String[]并从中提取数据。

这是客户端导入的文件,包含检索数据的方法:

@WebService(name = "Functions", targetNamespace = "http://example.com/")
@XmlSeeAlso({
    ObjectFactory.class
})
public interface Functions {


/**
 * 
 * @return
 *     returns java.util.List<com.example.StringArray>
 */
@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "getData", targetNamespace = "http://example.com/", className = "com.example.GetData")
@ResponseWrapper(localName = "getDataResponse", targetNamespace = "http://example.com/", className = "com.example.GetDataResponse")
@Action(input = "http://example.com/Functions/getDataRequest", output = "http://example.com/Functions/getDataResponse")
public List<String[]> getData();

这是在服务器上声明此函数的方式:

@WebMethod
public ArrayList<String[]> getData() {
    // invoked by android app
    dataStore = DatastoreServiceFactory.getDatastoreService();
    ArrayList<Entity> list = (ArrayList<Entity>) dataStore.prepare(query).asList(FetchOptions.Builder.withLimit(100));

    if (!list.isEmpty()) {
        ArrayList<String[]> res=new ArrayList<String[]>();
        String[] to_add;
        // convert entity into strings
        for (Entity current : list) {
            to_add=new String[3];
            to_add[0]=String.valueOf(current.getProperty(TEMP_ROW));
            to_add[1]=String.valueOf(current.getProperty(HUM_ROW));
            to_add[2]=String.valueOf(current.getProperty(DATE_ROW));

            res.add(to_add);
        }
        return res;
    }

    return null;
}
4

1 回答 1

0

您可以使用Collection中的toArray()方法

List<String> myList = myClient.getData();
String[] myArray = myList.toArray();
于 2013-09-01T07:00:10.423 回答