I'm trying to deserialize a response from an API.
[
{
"field1": "value a",
"field2": "value b"
},
{
"field1": "value c",
"field2": "value d`"
}
]
And I'm getting an error...
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'myProject.Models.MyDataModelRoot' because the type requires a JSON object to deserialize correctly. To fix this error either change the JSON to a JSON object or change the deserialzed type to an array or a type that implements a collection interface.
I need to make a data model that is representative of the data I'm getting back.
I've tried a couple samples of data models. Most of them need names and I dont have names... I tried a suggestion I read on here for a similar problem, but it did not work for me.
public class MyDataModelRoot : List<DataEntry>
{
}
public class DataEntry
{
[JsonProperty(ProperyName = "field1"]
public string Field1 { get; set; }
[JsonProperty(ProperyName = "field2"]
public string Field2 { get; set; }
}
HttpClient httpClient = specialHttpClient.GetHttpClient();
HttpClient.AddCredentials(creds)
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, apiuri)
MyDataModelRoot dataRoot = await.HttpClient.GetAsync<MyDataModelRoot>(request)
^^^ This is where it errors...