首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我尝试使用system.object查询时,CUCM返回ExecuteQueryReq

当我尝试使用system.object查询时,CUCM返回ExecuteQueryReq
EN

Stack Overflow用户
提问于 2020-06-13 21:01:50
回答 1查看 312关注 0票数 0

当我尝试从CUCM AXL api返回数据时,使用下面的代码

代码语言:javascript
复制
 ExecuteSQLQueryReq query = new ExecuteSQLQueryReq();

        query.sql = "select  * from systables ";

        string[] model = null;
        //get tables

        try
        {       
            executeSQLQueryResponse response = await client.executeSQLQueryAsync(query);

            model = response.executeSQLQueryResponse1.@return.Cast<string>().ToArray();               
        }
        catch (Exception ex)
        {
            Console.WriteLine($"\nError: getQuery: { ex.Message }");
            Environment.Exit(-1);
        }

        Console.WriteLine($"\ngetQuery: SUCCESS  model: { model }\n ");

我得到的是sytem.object[]而不是sql数据,我尝试使用下面的代码从每个数据中循环。

代码语言:javascript
复制
foreach ( string no in model)
{
    Console.WriteLine(no.ToString());
}

我得到的错误是:

无法将“System.Xml.XmlNode[]”类型的对象转换为“System.String”类型。

是否有一种方法可以在不进行前后转换的情况下返回数据?

我一直在学习这里的例子

如能提供任何帮助,将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2020-06-17 22:04:44

诀窍应该是将返回/行转换为“ElementNSImpl”,例如,如https://github.com/CiscoDevNet/axl-dotnet-samples上引用的示例所示

代码语言:javascript
复制
ExecuteSQLQueryReq query = new ExecuteSQLQueryReq();

// Set the text of the SQL query
query.setSql( "select name, pkid from applicationuser" );

// We'll use this list to receive the rows returned by the query
List<Object> user_list = null;

try {
    // Prepare a ExecuteSQLQueryRes object to receive the response from AXL
    ExecuteSQLQueryRes resp = axlPort.executeSQLQuery( query );

    // getRow() returns all of the rows as a List<Object> type
    user_list = resp.getReturn().getRow();

} catch ( Exception e ) {

}

// Create an iterator to cycle through each row, below
Iterator<Object> itr = user_list.iterator();

// While the iterator indicates there is at least one more row...
while ( itr.hasNext() ) {

    // The individual row object is of this ElementNSImpl type - we'll need to cast from generic Object here
    ElementNSImpl el = ( ElementNSImpl )itr.next();

    // Print out the formatted name and pkid values
    System.out.println(
        "Name: " + String.format( "%-20s", el.getElementsByTagName( "name" ).item( 0 ).getTextContent() )+
        " PKID: " + el.getElementsByTagName( "pkid" ).item( 0 ).getTextContent() );
}

尽管注意,示例基于Oracle Java 1.8,使用相同的版本通过wsimport从WSDL生成代码,并解析结果:

代码语言:javascript
复制
com.sun.org.apache.xerces.internal.dom.ElementNSImpl;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62365510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档