我正在开发一个调用soap函数并返回Diction<string, List<string>>
的android应用程序。
响应如下所示:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<retrieveDatabasesResponse xmlns="http://tempuri.org/">
<retrieveDatabasesResult xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>information_schema</a:Key>
<a:Value>
<a:string>CHARACTER_SETS</a:string>
<a:string>COLLATIONS</a:string>
<a:string>COLLATION_CHARACTER_SET_APPLICABILITY</a:string>
<a:string>COLUMNS</a:string>
<a:string>COLUMN_PRIVILEGES</a:string>
<a:string>ENGINES</a:string>
<a:string>EVENTS</a:string>
<a:string>FILES</a:string>
<a:string>GLOBAL_STATUS</a:string>
<a:string>GLOBAL_VARIABLES</a:string>
<a:string>KEY_COLUMN_USAGE</a:string>
<a:string>PARAMETERS</a:string>
<a:string>PARTITIONS</a:string>
<a:string>PLUGINS</a:string>
<a:string>PROCESSLIST</a:string>
<a:string>PROFILING</a:string>
<a:string>REFERENTIAL_CONSTRAINTS</a:string>
<a:string>ROUTINES</a:string>
<a:string>SCHEMATA</a:string>
<a:string>SCHEMA_PRIVILEGES</a:string>
<a:string>SESSION_STATUS</a:string>
<a:string>SESSION_VARIABLES</a:string>
<a:string>STATISTICS</a:string>
<a:string>TABLES</a:string>
<a:string>TABLESPACES</a:string>
<a:string>TABLE_CONSTRAINTS</a:string>
<a:string>TABLE_PRIVILEGES</a:string>
<a:string>TRIGGERS</a:string>
<a:string>USER_PRIVILEGES</a:string>
<a:string>VIEWS</a:string>
<a:string>INNODB_BUFFER_PAGE</a:string>
<a:string>INNODB_TRX</a:string>
<a:string>INNODB_BUFFER_POOL_STATS</a:string>
<a:string>INNODB_LOCK_WAITS</a:string>
<a:string>INNODB_CMPMEM</a:string>
<a:string>INNODB_CMP</a:string>
<a:string>INNODB_LOCKS</a:string>
<a:string>INNODB_CMPMEM_RESET</a:string>
<a:string>INNODB_CMP_RESET</a:string>
<a:string>INNODB_BUFFER_PAGE_LRU</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>boardies_password_manager</a:Key>
<a:Value>
<a:string>alarms</a:string>
<a:string>categories</a:string>
<a:string>passwords</a:string>
<a:string>settings</a:string>
<a:string>users</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>bugs</a:Key>
<a:Value>
<a:string>alarms</a:string>
<a:string>comments</a:string>
<a:string>logfile_history</a:string>
<a:string>platforms</a:string>
<a:string>privileges</a:string>
<a:string>reports</a:string>
<a:string>requested_features</a:string>
<a:string>settings</a:string>
<a:string>short_bulletins</a:string>
<a:string>software</a:string>
<a:string>users</a:string>
<a:string>versions</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>bugs_demo</a:Key>
<a:Value>
<a:string>alarms</a:string>
<a:string>comments</a:string>
<a:string>logfile_history</a:string>
<a:string>platforms</a:string>
<a:string>privileges</a:string>
<a:string>reports</a:string>
<a:string>requested_features</a:string>
<a:string>settings</a:string>
<a:string>software</a:string>
<a:string>users</a:string>
<a:string>versions</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>bugs_old</a:Key>
<a:Value>
<a:string>alarms</a:string>
<a:string>alarms_archive</a:string>
<a:string>comments</a:string>
<a:string>discussions</a:string>
<a:string>message_content</a:string>
<a:string>message_details</a:string>
<a:string>platforms</a:string>
<a:string>reports</a:string>
<a:string>settings</a:string>
<a:string>software</a:string>
<a:string>users</a:string>
<a:string>versions</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>critimon</a:Key>
<a:Value>
<a:string>administrators</a:string>
<a:string>alarms</a:string>
<a:string>android_devices</a:string>
<a:string>app_using_api_version</a:string>
<a:string>available_sdks</a:string>
<a:string>config_groups</a:string>
<a:string>config_items</a:string>
<a:string>config_values</a:string>
<a:string>crash_details</a:string>
<a:string>customer_queries</a:string>
<a:string>development_devices</a:string>
<a:string>generated_monthly_reports</a:string>
<a:string>registered_apps</a:string>
<a:string>sdk_versions</a:string>
<a:string>user_config_groups</a:string>
<a:string>user_config_items_18</a:string>
<a:string>user_config_values</a:string>
<a:string>users</a:string>
<a:string>windows_devices</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>email</a:Key>
<a:Value>
<a:string>alarms</a:string>
<a:string>alarms_archive</a:string>
<a:string>attachments</a:string>
<a:string>config_groups</a:string>
<a:string>config_items</a:string>
<a:string>config_values</a:string>
<a:string>queue</a:string>
<a:string>smtp_auth_users</a:string>
<a:string>smtp_debug_details</a:string>
<a:string>smtp_debug_record</a:string>
<a:string>users</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>email_something</a:Key>
<a:Value>
<a:string>alarms</a:string>
<a:string>attachments</a:string>
<a:string>authenticated_users</a:string>
<a:string>auto_replies</a:string>
<a:string>blacklist</a:string>
<a:string>emailqueue</a:string>
<a:string>logfile_history</a:string>
<a:string>settings</a:string>
<a:string>smtp_debug_details</a:string>
<a:string>smtp_debug_record</a:string>
<a:string>users</a:string>
<a:string>whitelist</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>email_test</a:Key>
<a:Value>
<a:string>alarms</a:string>
<a:string>attachments</a:string>
<a:string>authenticated_users</a:string>
<a:string>auto_replies</a:string>
<a:string>blacklist</a:string>
<a:string>emailqueue</a:string>
<a:string>logfile_history</a:string>
<a:string>settings</a:string>
<a:string>smtp_debug_details</a:string>
<a:string>smtp_debug_record</a:string>
<a:string>users</a:string>
<a:string>whitelist</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>email_user</a:Key>
<a:Value>
<a:string>alarms</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>emailserver</a:Key>
<a:Value>
<a:string>alarms</a:string>
<a:string>attachments</a:string>
<a:string>authenticated_users</a:string>
<a:string>auto_replies</a:string>
<a:string>blacklist</a:string>
<a:string>emailqueue</a:string>
<a:string>logfile_history</a:string>
<a:string>settings</a:string>
<a:string>smtp_debug_details</a:string>
<a:string>smtp_debug_record</a:string>
<a:string>users</a:string>
<a:string>whitelist</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>mysql</a:Key>
<a:Value>
<a:string>columns_priv</a:string>
<a:string>db</a:string>
<a:string>event</a:string>
<a:string>func</a:string>
<a:string>general_log</a:string>
<a:string>help_category</a:string>
<a:string>help_keyword</a:string>
<a:string>help_relation</a:string>
<a:string>help_topic</a:string>
<a:string>host</a:string>
<a:string>ndb_binlog_index</a:string>
<a:string>plugin</a:string>
<a:string>proc</a:string>
<a:string>procs_priv</a:string>
<a:string>proxies_priv</a:string>
<a:string>servers</a:string>
<a:string>slow_log</a:string>
<a:string>tables_priv</a:string>
<a:string>time_zone</a:string>
<a:string>time_zone_leap_second</a:string>
<a:string>time_zone_name</a:string>
<a:string>time_zone_transition</a:string>
<a:string>time_zone_transition_type</a:string>
<a:string>user</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>mysql_server_manager</a:Key>
<a:Value>
<a:string>alarms</a:string>
<a:string>config_groups</a:string>
<a:string>config_items</a:string>
<a:string>config_values</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>performance_schema</a:Key>
<a:Value>
<a:string>cond_instances</a:string>
<a:string>events_waits_current</a:string>
<a:string>events_waits_history</a:string>
<a:string>events_waits_history_long</a:string>
<a:string>events_waits_summary_by_instance</a:string>
<a:string>events_waits_summary_by_thread_by_event_name</a:string>
<a:string>events_waits_summary_global_by_event_name</a:string>
<a:string>file_instances</a:string>
<a:string>file_summary_by_event_name</a:string>
<a:string>file_summary_by_instance</a:string>
<a:string>mutex_instances</a:string>
<a:string>performance_timers</a:string>
<a:string>rwlock_instances</a:string>
<a:string>setup_consumers</a:string>
<a:string>setup_instruments</a:string>
<a:string>setup_timers</a:string>
<a:string>threads</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>software_audit_dev</a:Key>
<a:Value>
<a:string>fault_notes</a:string>
<a:string>faults</a:string>
<a:string>notes</a:string>
<a:string>software</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:KeyValueOfstringArrayOfstringty7Ep6D1>
<a:Key>test</a:Key>
<a:Value>
<a:string>fault_notes</a:string>
<a:string>file_history</a:string>
<a:string>my_table</a:string>
<a:string>stored_connections</a:string>
</a:Value>
</a:KeyValueOfstringArrayOfstringty7Ep6D1>
</retrieveDatabasesResult>
</retrieveDatabasesResponse>
</s:Body>
</s:Envelope>
我正在尝试获取elemenets的数量,所以我可以循环获取列表,但我尝试过的似乎不起作用。
以下是我正在使用的代码
private void processRetrievedDatabase(SoapObject soapResult)
{
int i = 0;
int j = 0;
SoapObject rootArray = ((SoapObject)soapResult.getProperty(0));
SoapObject dbArray = ((SoapObject)rootArray.getProperty(0));
int dbCount = dbArray.getPropertyCount();
ArrayList<String> databases = new ArrayList<String>();
while (i < dbCount)
{
if (i % 2 == 0)
{
databases.add(dbArray.getPropertyAsString(i));
Log.d(TAG, dbArray.getPropertyAsString(i));
}
else
{
SoapObject tablesArray = ((SoapObject)dbArray.getProperty(i));
int tableCount = tablesArray.getPropertyCount();
while (j < tableCount)
{
Log.d(TAG, tablesArray.getPropertyAsString(j));
j++;
}
}
i++;
}
以下是我在logcat中获得的内容
12-04 19:52:49.480: D/Soap Manager(6204): anyType{Key=information_schema; Value=anyType{string=CHARACTER_SETS; string=COLLATIONS; string=COLLATION_CHARACTER_SET_APPLICABILITY; string=COLUMNS; string=COLUMN_PRIVILEGES; string=ENGINES; string=EVENTS; string=FILES; string=GLOBAL_STATUS; string=GLOBAL_VARIABLES; string=KEY_COLUMN_USAGE; string=PARAMETERS; string=PARTITIONS; string=PLUGINS; string=PROCESSLIST; string=PROFILING; string=REFERENTIAL_CONSTRAINTS; string=ROUTINES; string=SCHEMATA; string=SCHEMA_PRIVILEGES; string=SESSION_STATUS; string=SESSION_VARIABLES; string=STATISTICS; string=TABLES; string=TABLESPACES; string=TABLE_CONSTRAINTS; string=TABLE_PRIVILEGES; string=TRIGGERS; string=USER_PRIVILEGES; string=VIEWS; string=INNODB_BUFFER_PAGE; string=INNODB_TRX; string=INNODB_BUFFER_POOL_STATS; string=INNODB_LOCK_WAITS; string=INNODB_CMPMEM; string=INNODB_CMP; string=INNODB_LOCKS; string=INNODB_CMPMEM_RESET; string=INNODB_CMP_RESET; string=INNODB_BUFFER_PAGE_LRU; }; }
12-04 19:53:01.896: D/Soap Manager(6204): anyType{Key=information_schema; Value=anyType{string=CHARACTER_SETS; string=COLLATIONS; string=COLLATION_CHARACTER_SET_APPLICABILITY; string=COLUMNS; string=COLUMN_PRIVILEGES; string=ENGINES; string=EVENTS; string=FILES; string=GLOBAL_STATUS; string=GLOBAL_VARIABLES; string=KEY_COLUMN_USAGE; string=PARAMETERS; string=PARTITIONS; string=PLUGINS; string=PROCESSLIST; string=PROFILING; string=REFERENTIAL_CONSTRAINTS; string=ROUTINES; string=SCHEMATA; string=SCHEMA_PRIVILEGES; string=SESSION_STATUS; string=SESSION_VARIABLES; string=STATISTICS; string=TABLES; string=TABLESPACES; string=TABLE_CONSTRAINTS; string=TABLE_PRIVILEGES; string=TRIGGERS; string=USER_PRIVILEGES; string=VIEWS; string=INNODB_BUFFER_PAGE; string=INNODB_TRX; string=INNODB_BUFFER_POOL_STATS; string=INNODB_LOCK_WAITS; string=INNODB_CMPMEM; string=INNODB_CMP; string=INNODB_LOCKS; string=INNODB_CMPMEM_RESET; string=INNODB_CMP_RESET; string=INNODB_BUFFER_PAGE_LRU; }; }
我几乎就在那里但它应该打印出数据库,然后是log cat中的所有表并重复但是由于某种原因它只打印第一个数据库及其表。
所以在我上面的例子中,它应该打印
information_schema
CHARACTER_SETS
COLLATIONS
COLLATION_CHARACTER_SET_APPLICABILITY
etc
etc
boardies_password_manager
alarms
categories
passwords
etc
etc
但我只获取information_schema及其表而不是其他数据库
感谢您提供的任何帮助。
答案 0 :(得分:4)
如果我理解正确,它只打印第一个数据库,因为在为下一个表启动循环之前j
变量没有重置为0。所以,else块应该是这样的:
else
{
SoapObject tablesArray = ((SoapObject)dbArray.getProperty(i));
int tableCount = tablesArray.getPropertyCount();
// j should reset to 0
j = 0;
while (j < tableCount)
{
Log.d(TAG, tablesArray.getPropertyAsString(j));
j++;
}
}
或者你可能想要这样的for循环(我喜欢这种方式,因为它比以前更简单,更清晰):
private void processRetrievedDatabase(SoapObject soapResult)
{
SoapObject rootArray = ((SoapObject)soapResult.getProperty(0));
SoapObject dbArray = ((SoapObject)rootArray.getProperty(0));
int dbCount = dbArray.getPropertyCount();
ArrayList<String> databases = new ArrayList<String>();
for(int i = 0; i < dbCount; i++){
if (i % 2 == 0)
{
databases.add(dbArray.getPropertyAsString(i));
Log.d(TAG, dbArray.getPropertyAsString(i));
}
else
{
SoapObject tablesArray = ((SoapObject)dbArray.getProperty(i));
int tableCount = tablesArray.getPropertyCount();
for(int j = 0; j < tableCount; j++){
Log.d(TAG, tablesArray.getPropertyAsString(j));
}
}
}
}
答案 1 :(得分:1)
我似乎不清楚你是如何解析SoapObjects的 我不确定你需要一个模数。显然你猜测所有奇数属性都是键,而所有偶数属性都是值列表。我不确定这是最好的方式
首先,您可以尝试打印dbCount和tableCount的值。它们是你所期望的那样。 然后你应该改变
Log.d(TAG, dbArray.getPropertyAsString(i));
和
Log.d(TAG, tablesArray.getPropertyAsString(j));
设置不同的标签,以便您知道哪一个正在打印。
这将帮助您找到代码未完全按照您希望的方式执行的操作,并且可能会返回结果,以便我们可以尝试找到更多的想法。
祝你好运