I am trying to fetch data from my server. It is returned as JSON:
item {{ "name": "Event1", "tblEventID": "1", "timeCreated": "2021-08-03 11:47:16", "timeUpdated": "2021-08-05 15:08:19", "userID": "6", "description": "Ein ganz toller Event", "venueName": "TollesVenue", "venueAdresse": "VenueStraße in Straßburg", …}
I tried serializing object like so:
public static List<EventType> Deserialize(ApiResponse response)
{
List<EventType> ad = new List<EventType>();
var array = (Newtonsoft.Json.Linq.JArray)response.payload;
foreach (var item in array)
{
EventType x = (EventType)(item.ToObject(typeof(EventType)));
ad.Add(x);
}
return ad;
}
But I am getting the error:
Could not convert string to boolean: 1. Path 'payload[0].displayStartTime'.
So it is failing while trying to convert the string "1" into my eventType where "displayStartTime" is ofc a bool.
Now I can make my type a string and it works fine, but thats not the point. I want to keep it as bool in my model.
However, Since I am basically using one line of code:
EventType x = (EventType)(item.ToObject(typeof(EventType)));
To make the conversion, I cannot access the single steps and intercept the bool / string missmatch.
How could I parse the object, keeping the bool in the model and deserializing the whole json?