I am trying to deserialize a GraphQLResponse in c#.
My response contains the following:
{
"myClassObjects": [
{
"var1": "var1Value",
"var2": "var2Value"
}, //more MyClass objects
]}
According to several sources, I should now be able to unpack and deserialize this using:
var output = response.getDataFieldAs<IEnumerable<MyClass>>("myClassObjects");
Sadly, the getDataFieldAs method does not exist (anymore).
The response.Data is a Newtonsoft.Json.Linq.JObject which contains an object "myClassObjects" which is an array of MyClass objects. When I try to unpack :
List<MyClass> output = JsonConvert.DeserializeObject<List<MyClass>>(response.Data.ToString());
I keep getting :
Cannot deserialize the current JSON object ... because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly
It's my first time working with Json and I really hope there is a handy sollution for this ? Any help would be much appreciated.