'r' is invalid after a value. Expected either ',', '}', or ']'

Advertisements

I am trying to Deserialize string to class with this structure:

  // this is my json
    {
      "MethodName":"PRC_SET_COMMISSION_STATIC",
      "Input":"{"reqType":"U","sapId":17000100,"offerType":5,"commissionRate":4,"accountNo":null,"fromDate":"2022-05-29T00:00:00","toDate":"2029-05-29T00:00:00","userId":"13601360"}"}

And this is my class which I want to get this values:

public class ProcessRequestRequestModelCl :AuthenticationModelCl
    {
        public string MethodName { get; set; }
        public string Input { get; set; }
    }

So what I do to achieve this is something like this:

ProcessRequestRequestModelCl RequestModel = System.Text.Json.JsonSerializer.Deserialize<ProcessRequestRequestModelCl>(ParameterStr);

but I get this error: ‘r’ is invalid after a value. Expected either ‘,’, ‘}’, or ‘]’
problem is something with "Input":"{"reqType":"U","sapId":17000100,"offerType":5,"commissionRate":4,"accountNo":null,"fromDate":"2022-05-29T00:00:00","toDate":"2029-05-29T00:00:00","userId":"13601360"}" . I was wondering how should I Pass json as string to input value.

>Solution :

If you really need to have the inner json as a string, you need to escape the qutoes like this:

{
    "MethodName":"PRC_SET_COMMISSION_STATIC",
    "Input": "{\"reqType\":\"U\",\"sapId\":17000100,\"offerType\":5,\"commissionRate\":4,\"accountNo\":null,\"fromDate\":\"2022-05-29T00:00:00\",\"toDate\":\"2029-05-29T00:00:00\",\"userId\":\"13601360\"}"
}

Leave a ReplyCancel reply