I am working with Auth0 Management API endpoints, the issue with this one.
Here is my rest code.
var client = new RestClient(tempapiendpoint);
var request = new RestRequest(Method.GET);
request.AddHeader(header, bearerstring);
request.AddParameter(specificfieldname,specificfields);
request.AddParameter(includefieldname, includetrueorfalse);
IRestResponse response = await client.ExecuteAsync(request);
var myDeserializedClass = JsonConvert.DeserializeObject<Root>(response.Content);
I have the following response.
[
{
"email": "somevalue",
"name": "somevalue",
"nickname": "somevalue",
"user_id": "somevalue"
},
{
"email": "somevalue",
"name": "somevalue",
"nickname": "somevalue",
"user_id": "somevalue"
},
{
"email": "somevalue",
"name": "somevalue",
"nickname": "somevalue",
"user_id": "somevalue"
}
]
At this point, I use an online class generator, such as, https://json2csharp.com/
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class MyArray {
[JsonProperty("email")]
public string Email;
[JsonProperty("name")]
public string Name;
[JsonProperty("nickname")]
public string Nickname;
[JsonProperty("user_id")]
public string UserId;
}
public class Root {
[JsonProperty("MyArray")]
public List<MyArray> MyArray;
}
and everytime, I get the same error.
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'RandomStuffGeneratorPrivate.POCO.Root' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.
A few more things I have tried.
Looks to me that you are deserializing to the wrong class, try using : JsonConvert.DeserializeObject<MyArray[]>(myJsonResponse)