I am trying to get the value from Dictionary(JSON deserialized) and parse it as long.
When I quick viewed the variable I found there is no "M" as part of the out parameter a s given below
But when I click into the value, I found "M" being added to the value as given
The problem here is the long.Parse fails when there is "M". If I remove "M" manually long.Parse works fine.
Why this strange behavior? and how to avoid this?
Edit:
Value in payloadJson is
{
"http://schemas.microsoft.com/ws/2008/06/identity/claims/userdata": "admin@admin.com",
"expiry": 1551354842.0,
"issuedAt": 1551351242.0,
"notBefore": 1566989642.0,
"isRefresh": false
}
var payloadData = jsonSerializer.Deserialize<Dictionary<string, object>>(payloadJson);
object exp;
if (payloadData != null && (checkExpiration && payloadData.TryGetValue("expiry", out exp)))
{
var validTo = FromUnixTime(long.Parse(exp.ToString()));
}
Console app
using JWT;
using JWT.Serializers;
using System.Collections.Generic;
using System.Web.Script.Serialization;
namespace TestApp
{
class Program
{
static void Main(string[] args)
{
var token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3VzZXJkYXRhIjoiYWRtaW5AYWRtaW4uY29tIiwiZXhwaXJ5IjoxNTUxMzU0ODQyLjAsImlzc3VlZEF0IjoxNTUxMzUxMjQyLjAsIm5vdEJlZm9yZSI6MTU2Njk4OTY0Mi4wLCJpc1JlZnJlc2giOmZhbHNlfQ.E-fR8VAFAy-mosEfQC3ZPlN2kZBQg02FLYuChdhqHNhzgVsbIjMXUFLHYowf0aUwQRcyoFR2mpiD_5I6drGdnQ";
var jsonSerializer = new JavaScriptSerializer();
IJsonSerializer serializer = new JsonNetSerializer();
IDateTimeProvider provider = new UtcDateTimeProvider();
IJwtValidator validator = new JwtValidator(serializer, provider);
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder);
var payloadJson = decoder.Decode(token, "GAFaS9W4Ys2AA2VHadPdje9gaeWjY8", true);
var payloadData = jsonSerializer.Deserialize<Dictionary<string, object>>(payloadJson);
object exp;
payloadData.TryGetValue("expiry", out exp);
var tempExpiry = long.Parse(exp.ToString());
}
}
}