C#MVC对象语法

本文关键字:语法 对象 C#MVC | 更新日期: 2023-09-27 18:29:55

我正在尝试使用下面github链接中的JWT Encode函数。这个JWT由谷歌钱包使用,令牌的最后一部分是一个对象。有人能帮我提供"请求"部分的正确语法吗。visual studio编辑器中出现语法错误。

         public static string CreateJWT(int JobID)
   {
       var payload = new Dictionary<string, object>() {
            { "iss", "17114776323338359428" },
            { "aud", "Google" },
            { "typ", "google/payments/inapp/item/v1" },
            { "exp", "1309988959" },
            { "iat", "1409988959" },
            { "request", 
                  "name", "Piece of Cake",
                  "description", "Virtual chocolate cake to fill your virtual tummy",
                  "price", "10.50",
                  "currencyCode", "USD",
                  "sellerData", "user_id:1224245,offer_code:3098576987,affiliate:aksdfbovu9j" 
            }
        };
        var secretKey = "s_F084...";
        string token = JWT.JsonWebToken.Encode(payload, secretKey, JWT.JwtHashAlgorithm.HS256);
        return token;
   }

C#MVC对象语法

不确定这是不是……但我会试一试。

你有Dictionary<string, object>。。然而这里:

{ "request", // missing "object" part..
    { "name", "Piece of Cake" },
    { "description", "Virtual chocolate cake to fill your virtual tummy" },
    { "price", "10.50" },
    { "currencyCode", "USD" },
    { "sellerData", "user_id:1224245,offer_code:3098576987,affiliate:aksdfbovu9j" } 
}

也许可以尝试将其更改为:

{ "request", new Dictionary<string, object>() { // another dictionary.
        { "name", "Piece of Cake" },
        { "description", "Virtual chocolate cake to fill your virtual tummy" },
        { "price", "10.50" },
        { "currencyCode", "USD" },
        { "sellerData", "user_id:1224245,offer_code:3098576987,affiliate:aksdfbovu9j" } 
    }
}

我想这不是初始化KeyValuePair<string, object>:的有效方法

        { "request", 
              "name", "Piece of Cake",
              "description", "Virtual chocolate cake to fill your virtual tummy",
              "price", "10.50",
              "currencyCode", "USD",
              "sellerData", "user_id:1224245,offer_code:3098576987,affiliate:aksdfbovu9j" 
        }

你是说像这样动态的东西吗

        { "request", new {
              name = "Piece of Cake",
              description = "Virtual chocolate cake to fill your virtual tummy",
              price = "10.50",
              currencyCode = "USD",
              sellerData = "user_id:1224245,offer_code:3098576987,affiliate:aksdfbovu9j" 
            }
        }