How can I just upload the contents of a List

0

I have a Web service in which the result is a <List> . I can get the result without problems. What I'm looking to do is just show me the result depending on the value of the result is equal to 1.

Here is the structure of the Web service and what it shows in the result:

<Response>
    <List>
        <anyType xsi:type="xsd:string">Q9Row1</anyType>
        <anyType xsi:type="xsd:string">Q9Comment1</anyType>
        <anyType xsi:type="xsd:string">Q10Row1</anyType>
        <anyType xsi:type="xsd:string">Q10Comment1</anyType>
        <anyType xsi:type="xsd:string">Q11Row1</anyType>

    </List>
</Response>
<Response>
    <List>
        <anyType xsi:type="xsd:string">1</anyType>
        <anyType xsi:type="xsd:string">2</anyType>
        <anyType xsi:type="xsd:string">2</anyType>
        <anyType xsi:type="xsd:string">1</anyType>
        <anyType xsi:type="xsd:string">1</anyType>
    </List>
</Response>

What I want is that if in <Q9Row1> the result is 1 in <anyType xsi:type="xsd:string">1</anyType> show me the result. If the result is other than 1. That the program does not show me anything.

Here is the form which I originally called the service before getting what I mention.

public static string arrayToString(object[] array)//overload
{
    string s = "";
    for (int i = 0; i < array.Length; ++i)
    {
        s += array[i].ToString() + " , ";
    }
    if (s.Length > 3) { s = s.Substring(0, s.Length - 3); }
    return s;
}

WebRefernce.DashboardSoapClient db = new WebRefernce.DashboardSoapClient();

WebRefernce.Response[] resp = db.GetResponse();

for (int i = 0; i < resp.Length; ++i)
{
    textBox1.Text += Form1.arrayToString(resp[i].List);
}

What I originally do is just post the result. Now I'm looking to post it but only show when = 1

As much as Q9Row1 and 1 are values from the list. The Q9Row1 is the header of the answer and the 1 is the result of this. But both are non-property values.

I included a screenshot of the result of resp.

The first screenshot shows as poster the Q9Row1 in the first string I require.

This second screenshot shows when the result happens for the second time in for resp.Length and there it shows me the 1

Is there any way to do this in C #?

    
asked by A arancibia 25.01.2017 в 18:25
source

2 answers

0

You can filter the results using LinQ, assuming you receive the list in a variable of type List<ClaseServicioWeb> :

List<ClaseServicioWeb> listaObtenida = (List<ClaseServicioWeb>)listaObtenida.Where(t => t.Q9Row1 == "1").ToList();

Note: you must make use of the System.linq reference by adding it to the beginning of your file with using System.Linq;

Update

Changing the cycle for for a foreach we can obtain the desired result:

WebRefernce.Response[] resp = db.GetResponse();

foreach(var item in resp.Where(t => t.CampoQueDeseasFiltrar == "1").ToList())
{
    textBox1.Text += Form1.arrayToString(item.List);
}

Where the CampoQueDeseasFiltrar should be changed by the name of the attribute you want to filter

    
answered by 25.01.2017 в 18:34
0

Maybe that's how it works for you:

for (int i = 0; i < resp.Length; ++i)
{
    if (resp[i].ToString().Equals("1"))
        textBox1.Text += Form1.arrayToString(resp[i].List);
}
    
answered by 25.01.2017 в 19:34