I want only value part in c#. Like from 40150:Resource, I just need 40150.
You can refer to the following code to extract data from your example string.
var selectedval = "40150:Resource";
var code = selectedval.Split(':')[0];
With Regards,
Fei Han
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Now all the values of the json can be accessed using the class object called rootObject.
You can also refer this tutorial which does this same thing.
Helping you always. Don't forget to click "Mark as Answer" on the post that helped you.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠
Participant
1444 Points
2835 Posts
How to get value not text from the jason result result
Jun 07, 2019 07:26 AM|demoninside9|LINK
Hi All,
I got @Html.ListBox items and their values by using jquery. The format for data like below
40150:Resource,40153:Country Admin Assign,40161:Cross Country Request,40151:Email Logs,40154:AV Programme,40158:Country Module Management Report,40160:User Report,40149:Role Settings
I want only value part in c#. Like from 40150:Resource, I just need 40150.
And I need to access all values.
All-Star
40565 Points
6233 Posts
Microsoft
Re: How to get value not text from the jason result result
Jun 07, 2019 09:11 AM|Fei Han - MSFT|LINK
Hi demoninside9,
You can refer to the following code to extract data from your example string.
With Regards,
Fei Han
Participant
1253 Points
935 Posts
Re: How to get value not text from the jason result result
Jun 09, 2019 03:10 AM|yogyogi|LINK
First you create your class based on the json structure which you have. You can do this by using this online tool called - http://json2csharp.com/.
Next in your project, after you have read the json, you can Deserialize it by using JsonConver.cs class. Check the below code:
Now all the values of the json can be accessed using the class object called rootObject.
You can also refer this tutorial which does this same thing.
♠ ASP.NET Core Tutorials → Start from the Beginning and become an Expert in 30 days time ♠