I have a problem Deserialising a JSON string to a List
the TCProject is as follows:
[JsonObject(MemberSerialization.OptIn)]
public class TCProject
{
public override string ToString()
{
return Name;
}
[JsonProperty(PropertyName = "archived")]
public bool Archived { get; set; }
[JsonProperty(PropertyName = "description")]
public string Description { get; set; }
[JsonProperty(PropertyName = "href")]
public string Href { get; set; }
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "webUrl")]
public string WebUrl { get; set; }
}
The JSON string looks as follows:
{"project":[{"name":"GCUK","id":"project11","href":"/httpAuth/app/rest/projects/id:project11"},{"name":"Interiors In Spain","id":"project3","href":"/httpAuth/app/rest/projects/id:project3"}]}
the code to convert the string is as follows:
public IEnumerable<TCProject> GetAllProjects()
{
var uri = _connection.CreateUri("/httpAuth/app/rest/projects");
var request = _connection.Request(uri);
var projects = JsonConvert.DeserializeObject<List<TCProject>>(request);
return projects;
}
The exception I am getting:
Newtonsoft.Json.JsonSerialisationException: {“Cannot deserialize JSON object into type ‘System.Collections.Generic.List`1[TCProject]’.”}
there has got to be something really easy that i’m missing – anyone got any ideas?
I am pretty sure if you created a class with one property called project and that was a List and deserialized to that object, that everything would just work.