質問

I am trying to use a JWT Encode function from the github link below. This JWT is used by Google Wallet and the last section of the token is an object. Can someone help me with the correct syntax for the "request" section. I am getting a syntax error in the visual studio editor.

         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;
   }
役に立ちましたか?

解決

Not sure if this is it.. but I'll give it a crack.

You have Dictionary<string, object>.. yet here:

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

Perhaps try changing it to this:

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

他のヒント

I guess this is not a valid way to initialize a 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" 
        }

Did you mean something dynamic like

        { "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" 
            }
        }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top