'r' 后一个值无效。应为 ',', '}' 或 ']'
'r' is invalid after a value. Expected either ',', '}', or ']'
我正在尝试使用以下结构将字符串反序列化为 class:
// 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"}"}
这是我的class,我想得到这个值:
public class ProcessRequestRequestModelCl :AuthenticationModelCl
{
public string MethodName { get; set; }
public string Input { get; set; }
}
所以我为实现这一目标所做的事情是这样的:
ProcessRequestRequestModelCl RequestModel = System.Text.Json.JsonSerializer.Deserialize<ProcessRequestRequestModelCl>(ParameterStr);
但我收到此错误:'r' 在值后无效。应为“,”、“}”或“]”
问题出在 "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"}"
上。我想知道我应该如何将 json 作为字符串传递给输入值。
如果您确实需要将内部 json 作为字符串,则需要像这样转义 qutoes:
{
"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\"}"
}
我正在尝试使用以下结构将字符串反序列化为 class:
// 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"}"}
这是我的class,我想得到这个值:
public class ProcessRequestRequestModelCl :AuthenticationModelCl
{
public string MethodName { get; set; }
public string Input { get; set; }
}
所以我为实现这一目标所做的事情是这样的:
ProcessRequestRequestModelCl RequestModel = System.Text.Json.JsonSerializer.Deserialize<ProcessRequestRequestModelCl>(ParameterStr);
但我收到此错误:'r' 在值后无效。应为“,”、“}”或“]”
问题出在 "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"}"
上。我想知道我应该如何将 json 作为字符串传递给输入值。
如果您确实需要将内部 json 作为字符串,则需要像这样转义 qutoes:
{
"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\"}"
}