I've created a dll that perform some request on my API. Now the request send me back a json response, what I want to do (from the dll), is return an array of object to be used in the program that implements the DLL. Now I've this class:
public class Details
{
public string name { get; set; }
public string age { get; set; }
}
public class Info
{
public List<object> info { get; set; }
}
public class User
{
public Details details { get; set; }
public Info info { get; set; }
}
public class RootObject
{
public User user { get; set; }
}
I deserialize the request like this:
var obj = JsonConvert.DeserializeObject<List<RootObject>>("json returned");
Now the json contains the details of the user, and in some case also the info, so I iterate through of it in this way:
foreach(var user in obj)
{
item.user.details.name;
//take some info (could not contain nothing)
foreach(var info in user.info.info)
{
info; //<- contains all the information
}
}
What I want to know is: How can I create a list of object? In particular I want send back the user object that have as property details and info. The result should be an array of object 'cause who reiceve the object need to iterate through of it and read each object property as:
user[0].details.name: //where 0 is the index of the user (php syntax)
I don't know if is possible in c#, someone could help me to achieve this target?
var users = obj.Select(x => x.user).ToArray();