How to Split The Token (Only) In asp.net?
this my Requirement:
-------------------------
{"meta":
{
"code":"AH000",
"description":"Success",
"status":0
},
"data":{
"token":"MjQzMjYxMjQzMTMyMjQ0ZDRkNTIzMDc5NjY2ODU1NzQ2NDU4NDk3MzcyNzY1OTRhNjE2YTQyNzg2NTY5NTk2Yjc1NTY0YzM3NTI1OT",
"tokenType":"SESSION",
"expiresIn":86400
}
}

Rajkiran SwainRank #165 · 14.4K reputationPosted May 4, 2023, 7:40 AM EDT
using Newtonsoft.Json.Linq; // assuming the JSON string is stored in a variable named jsonString JObject json = JObject.Parse(jsonString); string token = (string)json["data"]["token"];Tuhin PaulRank #7 · 71.9K reputationPosted May 4, 2023, 8:17 AM EDT
To split the token in ASP.NET, you can use the `Newtonsoft.Json` package to deserialize the JSON string into a C# object and then access the `token` property.
using Newtonsoft.Json.Linq; // JSON string string jsonString = "{\"meta\":{\"code\":\"AH000\",\"description\":\"Success\",\"status\":0},\"data\":{\"token\":\"MjQzMjYxMjQzMTMyMjQ0ZDRkNTIzMDc5NjY2ODU1NzQ2NDU4NDk3MzcyNzY1OTRhNjE2YTQyNzg2NTY5NTk2Yjc1NTY0YzM3NTI1OT\",\"tokenType\":\"SESSION\",\"expiresIn\":86400}}"; // Deserialize the JSON string JObject jsonObject = JObject.Parse(jsonString); // Get the token value string token = (string)jsonObject["data"]["token"];We are first parsing the JSON string into a `JObject` using the `JObject.Parse` method. We can then access the `token` property by indexing into the object using the property name as a key. The resulting `token` variable will contain the value of the `token` property, which in this case is the long string of characters.