I have the following JSON object and I have been trying to convert it to a datatype, Say MessageData in C# but I keep getting the error that says
The best overloaded method match for 'Newtonsoft.Json.JsonConvert.DeserializeObject(string)' has some invalid arguments.
The JSON is as follows:
{
{
"SMSMessageData": {
"Message": "Sent to 1/1 Total Cost: NGN 4.4000",
"Recipients": [
{
"statusCode": 102,
"number": "+2348033776502",
"cost": "NGN 4.4000",
"status": "Success",
"messageId": "ATXid_b96d58d359d2e12ad0b9696cee7630ce"
}
]
}
}
}
MessageResponse is as follows below
public class MessageResponse
{
public List<SMSMessageData> Data { get; set; }
}
public class SMSMessageData
{
public string Message { get; set; }
public List<SMSRecipient> Recipients { get; set; }
}
public class SMSRecipient
{
public int StatusCode { get; set; }
public string PhoneNumber { get; set; }
public string Cost { get; set; }
public string StatusMessage { get; set; }
public string MessageId { get; set; }
}
This is how I am trying to deserialize it
var response= JsonConvert.DeserializeObject<MessageResponse>(json)
From the comments, it seems the problem is from the extra enclosing curly braces which I have not found a way to remove so far. I am not able to do json.ToString() and without converting it to string, I am not able to apply Trim or any other String methods to remove the extra enclosing curly braces.
Please I need assistance on how to successfully convert this to the MessageResponse data.
I am running it on ASP.Net Core 3.1
Thank you
