Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Posted
Updated 11-Sep-19 1:58am
v2
Comments
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

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"];
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900