Click here to Skip to main content
14,300,549 members
Rate this:
Please Sign up or sign in to vote.
See more:
result of jsonToken = {{"alg":"none","typ":"JWT"}.{"user":{"id":"Admin"}}}

this line of code exist below

var user = jsonToken.Claims.First(claim => claim.Type == "user").Value;

return {"id":"admin"}

i need to get value of id meaning i need to return Admin

You could convert user string to JObject and get the children like below:

What I have tried:

var user = jsonToken.Claims.First(claim => claim.Type == "user").Value;
var obj = JObject.Parse(user);
var id = obj.Children().Children();

meaning i need value of id as Admin
Updated 11-Sep-19 1:58am
Mohibur Rashid 10-Sep-19 17:41pm
Your json looks incorrect
There is dot in place of comma and top object absolutely wrong.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

This works, but only if the input string is correctly formatted:
string json2 = @"{ 'alg':'none','typ':'JWT','user':{'id':'Admin'}}";
dynamic dj = JsonConvert.DeserializeObject<dynamic>(json2);
var user = dj["user"];
string id = user["id"];

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100