I have a JSON with the following content:
{"SMTP Host: ":"host","SMTP Port: ":"123","SMTP User Name: ":"ionut","SMTP User Password: ":"pass","SMTP From: ":"robert","SMTP Display Name: ":"aeg","d":"2022-05-25T11:24:06.459Z"}
What I want is to get the values of the JSON (host, 123, etc)in my app. What I have tried is:
public class Root
{
public string smtpHost { get; set; }
public string smtpPort { get; set; }
public string smtpUserName { get; set; }
public string smtpPassword { get; set; }
public string smtpFrommtpHost { get; set; }
public string smtpDisplayName { get; set; }
}
public class CustomDocumentOperationService : DocumentOperationService
{
DocumentOperationResponse SendEmail(MailAddressCollection recipients, string subject, string messageBody, Attachment attachment)
{
using (StreamReader sr = new StreamReader(System.Web.HttpContext.Current.Server.MapPath("~/JSON/my-download.json")))
{
List<Root> contentJSON = JsonConvert.DeserializeObject<List<Root>>(sr.ReadToEnd());
System.Diagnostics.Debug.WriteLine("***************************************contentJSON: " + contentJSON + "***************************************");
}
/*I have tried also with the following 2line, but I get the error
'Unexpected character encountered while parsing value: C. Path '', line 0, position 0.'*/
//Root friends = JsonConvert.DeserializeObject<Root>(System.Web.HttpContext.Current.Server.MapPath("~/JSON/my-download.json"));
//System.Diagnostics.Debug.WriteLine("***************************************contentJSON: " + friends + "***************************************");
//Here I want to get the values from JSON:
string SmtpHost = "mail.test.com";
int SmtpPort = 112;
string SmtpUserName = "ionut@test.com";
string SmtpUserPassword = "blablabla";
string SmtpFrom = "ionut@test.com";
string SmtpFromDisplayName = "Ionut";
}
}
Using this method, I get the following exception:
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List
1`. I know there's a topic about it, but it couldn't help solve the issue. What am I missing?