I have a basic JSON message format of:
{
"MessageName":"blah",
"Version":"1.2",
"TimeStamp":"2020-07-22T12:44:19.416+01:00",
"UniqueID":"5a8988db-ed23-40f8-a2cd-ae57ecf8aa67",
"Source":"ja9999",
"Target":null,
"RequestID":null,
"MessageBody":{
"something1":"blah",
"something2":"blan",
"etc":"blah",
}
}
I want to deseralise the JSON but, and this is where I get stuck, all the data under MessageBody needs to be a single string still in JSON format. The reason being is that the MessageBody varies with each message. The plan is to then store each deserailised set of data in to fields in a database. Where each field is:
- MessageName : text
- Version : text
- Timestamp : date/time
- UniqueId : text
- Source : text
- Target : text
- RequestId : text
- MessageBody : JSON-coded text
When I run my code I fallover at the { inside MessageBody.
my code is:
public class Root
{
public string MessageName { get; set; }
public string Version { get; set; }
public DateTime TimeStamp { get; set; }
public string UniqueID { get; set; }
public string Source { get; set; }
public string Target { get; set; }
public string RequestID { get; set; }
public string MessageBody { get; set; }
}
var o = JsonConvert.DeserializeObject<Root>(jsonString);
I am new to JSON and c# so any hints would be appreciated. Thanks