'Find values in a JSON string using VB.Net
I’m a novice and am struggling to work out how to use the Newtonsoft JSON methods to pull out of this JSON string what I’m after with VB.Net. The first thing to note is that the JSON is in two parts, the Total and then the results.
"{""total"":9,""results"":[{""id"":1334,""description"":""Fiat"",""type"":0},{""id"":1331,""description"":""Ford"",""type"":0},{""id"":1330,""description"":""Nissan"",""type"":0},{""id"":1335,""description"":""Project Alpha"",""type"":0},{""id"":1336,""description"":""Project Beta"",""type"":0},{""id"":1337,""description"":""Project Gamma"",""type"":0},{""id"":1333,""description"":""Tesla"",""type"":0},{""id"":1332,""description"":""Toyota"",""type"":0},{""id"":1329,""description"":""Volkswagen"",""type"":0}]}"
What I want to do is search the JSON for a particular description and get back the ID. For example if I searched for “Toyota” I would get back “1332”. I have looked at the examples on this and other forums but failed to get any to work for me. BTW I note that I could loop through the children in the ‘results’ but looping seems inefficient so I’m hoping to use a more efficient method.
Solution 1:[1]
- First create an Object representing your Json (copy your json to clipboard, in Visual Studio create an empty class and paste it as json classes Edit -> Paste Spacial -> paste json as class - I have a german VS, so maybe the menu is named differently)
- Deserialize the json string in a new instance of this class
- do your filtering as you need
I made a sample app for you on GitHub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
