Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return a single object with an array and a list?

Tags:

c#

I have a list and an array that I would like to return, but I'm unsure how to bring the two together. I have deserialized my JSON and created two objects. How do I bring this list and array together in a single object? :

var one = JsonConvert.DeserializeObject<MyData.RootObject>(first);
var two = JsonConvert.DeserializeObject<MyData.RootObject>(second);

List<myData.DataOne> listOne = new List<myData.DataOne>();

foreach (var items in one) 
{
     someDataModel model = new someDataModel();
     model.property = one.rows.f[0].v;
     listOne.Add(model);
}

string[] array = new string[two.rows.Count];

        for (var items = 0; items < two.rows.Count; items++)
        {
            array[items] = two.rows[items].f[0].v;
        }

return null;
like image 708
Fullmetal_Alchemist_Fan Avatar asked May 13 '26 19:05

Fullmetal_Alchemist_Fan


1 Answers

Create a new class to represent the combination of these two pieces of data:

public class MyReturnType 
{
    public List<myData.DataOne> ListOne {get;set;}
    public string[] Array {get;set;}
}

Then return it:

return new MyReturnType {ListOne = listOne, Array = array};
like image 112
StriplingWarrior Avatar answered May 16 '26 10:05

StriplingWarrior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!