' r'值之后是无效的。预期的是,要么是,','}' or&']'

发布于 2025-02-02 22:45:21 字数 1016 浏览 1 评论 0原文

我试图通过此结构将字符串供应到类:

  // 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"}"}

这是我想要获得此值的班级:

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,“ coundactno”:null,“ fromdate”:“” 2022-05-29T00:00:00“,” todate“:” 2029-05-29T00:00:00:00:00:00:00:“ userId”:“ 13601360”}“}”。我想知道我应该如何将JSON作为字符串传递给输入值。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有你我更好 2025-02-09 22:45:21

如果您确实需要将内部的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\"}"
}

If you really need to have the inner json as a string, you need to escape the quotes 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\"}"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文