I am a novice C# coder trying to use RestEase to call a RestAPI that returns an array e.g.[{“name”:”value}, {“name2”:”value2}] rather than a single {“name”:”value} response as per the example code provided at https://github.com/canton7/RestEase.
I get this error
JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type ‘DemoApi.User’ 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 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.
Please help with the syntax to accommodate this response in the context of the example provided in the RestEase example code here https://github.com/canton7/RestEase.
Many thanks in advance
Alain
I’ve tried the suggested types but my syntax is clearly not correct e.g. (e.g. ICollection, IList)
Alain Jaques is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.