I've developed a dll that allow me to use some method of my API. All working pretty well, but now I have a problem with linq. In particular I usually store all the results returned from the api in a list of object. So I can iterate through of it and get each item separated. Now I have this class:
public class Agent
{
public int id { get; set; }
public string name { get; set; }
}
public class RootObject
{
public List<Agent> agent { get; set; }
}
I deserialize the json like this:
var obj = JsonConvert.DeserializeObject<RootObject>(responseText);
return obj.Select(o => o.agent).ToList();
now I can deserialize the json correctly 'cause is a list of Agent but I can't use the method to return a list of object:
return obj.Select(o => o.agent).ToList();
the .Select is underlined in red, and the compiler tell me:
Agent.RootObject does not contain a definition for Select
if instead I use: var obj = JsonConvert.DeserializeObject<List<RootObject>>(responseText);
all the return line is underlined in red:
Can't convert System.Collections.Generic.List in System.Collections.Generic.List
so how can I fix this problem?
objis a singleRootObjectthen you'd wantobj.agent.Select(o => o.company), although I don't seecompanyanywhere in your class definitions,obj.Agent.