I have the following class that represents a table in an MSSQL database:
public string firstname { get; set; }
public string lastname { get; set; }
public string events { get; set; }
The 'events' property is actually an array of JSON objects serialized before storing in the table. Example row:
FirstName: Test
LastName: User
Events: [{"eventname":"event1","eventtype":"1"},{"eventname":"event2","eventtype":"2"}]
I need to return the contents of this table from a Web API call in JSON format to resemble:
[{
"firstname":"Test",
"lastname":"User",
"Events":[{"eventname":"event1","eventtype":"1"},{"eventname":"event2","eventtype":"2"}]
},
{...}]
Problem is when I do this, the events JSON property gets escaped and comes out as single string like this:
[{
"firstname":"Test",
"lastname":"User",
"Events":"[{\"eventname\":\"event1\",\"eventtype\":\"1\"},{\"eventname\":\"event2\",\"eventtype\":\"2\"}]
},
{...}]"
Obviously it's because the class for the events property is a string variable but not sure what I can do about that without having to loop through each row to re-format?