I created a class to deserialize this json
public class Self
{
public string href { get; set; }
}
public class Team
{
public string href { get; set; }
}
public class Links
{
public Self _self { get; set; }
public Team team { get; set; }
}
public class Player
{
public int id { get; set; }
public string name { get; set; }
public string position { get; set; }
public int jerseyNumber { get; set; }
public string dateOfBirth { get; set; }
public string nationality { get; set; }
public string contractUntil { get; set; }
public string marketValue { get; set; }
}
public class RootObject
{
public Links _links { get; set; }
public int count { get; set; }
public List<Player> players { get; set; }
}
public struct Player_Struct
{
public string id;
public string name;
public string position;
public int jerseyNumber;
public string dateOfBirth;
public string nationality;
public string contractUntil;
public string marketValue;
}
So, I created a function to create an HttpRequest and a relative object:
string requestUrl = teams.link_teams;
string responseText = parser.Request(requestUrl);
var obj = JsonConvert.DeserializeObject<Players.RootObject>(responseText);
Now the problem is that the compiler returns this exception:
Unhandled exception "Newtonsoft.Json.JsonSerializationException" in Newtonsoft.Json.dll
Ultralogization: you cannot deserialize the current JSON array (for example, [1,2,3]) to type "SF_DebugProject.API.Players + Links" because it requires a JSON object (for example, {"name": "value"}) to deserialize correctly.
, JSON JSON (, { "name": "value" }), , (, ICollection, IList), , JSON. JsonArrayAttribute , JSON.
'_links', 1, 11.
, fix , :
List<Players.RootObject> obj = JsonConvert.DeserializeObject<List<Players.RootObject>>(responseText);
rootobject, foreach. ?