我正面临来自Web服务的数组响应的问题 [英] i am facing a problem with a array response from a web service

查看:65
本文介绍了我正面临来自Web服务的数组响应的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Quote:

大家好我面临来自网络服务的数组响应问题,我调用了一个webmethod来返回一个集合数据形式的数据,现在这里的问题是,当我检查响应时,我发现数组中包含一个数组,数组中的数组,例如



--------外部数组-----------

数组[0] = [countryname]

数组[ 1] = [countryid]

array [2] = [locations] - > (位置由多个记录组成)

数组[3] = [issuccess]



在上面的示例中

数组[2] = [位置]还有一个数组



--------内部数组------- ----

array [0] = [locationid]

array [1] = [locationname]

array [2] = [ locationaddress]

array [3] = [locationphone]

array [4] = [issuccess]



请指导我如何将响应绑定在外部数组的不同数据表一个数据表中,另一个数据表用于内部数组

解决方案

< blockquote>您好,



也许下面的代码可以帮助您。



 class program 
{
static void Main(string [] args)
{
Object [] arrayInner = new object [5];
arrayInner [0] =1;
arrayInner [1] =伊斯坦布尔;
arrayInner [2] =地址;
arrayInner [3] =111111;
arrayInner [3] = true;

Object [] arrayOuter = new object [4];
arrayOuter [0] =土耳其;
arrayOuter [1] =90;
arrayOuter [2] = arrayInner;
arrayOuter [3] = true;

DataTable dataTableForOuter = new DataTable();
DataTable dataTableForInner = new DataTable();

for(int i = 0; i< arrayOuter.Length; i ++)
{
if(arrayOuter [i] .GetType()。IsArray)
{
dataTableForInner.Columns.Add(InnerData,typeof(object));
}
else
{
dataTableForOuter.Columns.Add(OuterData+ i,typeof(object));
}
}

}
}


Quote:

hi all i am facing a problem with a array response from a web service, i have invoked a webmethod which returns a collection of data in the form of arrays, now here what the problem is that when i checked the response i found that the array contains one more array in it, array with in array eg

--------Outer array-----------
array[0] = [countryname]
array[1] = [countryid]
array[2] = [locations] --> (location consists of multiple records)
array[3] = [issuccess]

here in the above example the
array[2] = [locations] has one more array in it

--------Inner array-----------
array[0] = [locationid]
array[1] = [locationname]
array[2] = [locationaddress]
array[3] = [locationphone]
array[4] = [issuccess]

please guide me how to bind the response in different datatable one datatable for outer array, and another datatable for inner array

解决方案

Hi,

Maybe the code below can help you.

class Program
  {
      static void Main(string[] args)
      {
          Object[] arrayInner = new object[5];
          arrayInner[0] = "1";
          arrayInner[1] = "Istanbul";
          arrayInner[2] = "Address";
          arrayInner[3] = "111111";
          arrayInner[3] = true;

          Object[] arrayOuter = new object[4];
          arrayOuter[0] = "Turkey";
          arrayOuter[1] = "90";
          arrayOuter[2] = arrayInner;
          arrayOuter[3] = true;

          DataTable dataTableForOuter = new DataTable();
          DataTable dataTableForInner = new DataTable();

          for (int i = 0; i < arrayOuter.Length; i++)
          {
              if (arrayOuter[i].GetType().IsArray)
              {
                  dataTableForInner.Columns.Add("InnerData", typeof(object));
              }
              else
              {
                  dataTableForOuter.Columns.Add("OuterData" + i, typeof(object));
              }
          }

      }
  }


这篇关于我正面临来自Web服务的数组响应的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆