Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value of JSON object in VB.net

Tags:

json

vb.net

I have the following code I would use in C#:

    var tokenJson = JsonConvert.SerializeObject(tokenJsonString);

    var jsonResult = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(jsonString);
    var firstItem = jsonResult["data"][0];

However, I have a VB.NET client, and I have no idea how to translate it. I have tried different online tools without a result.

I have a JSON response like this:

"{\"token\":\"1edd6006-678a-4e6a-ab65-4fa60efa8632\"}"

And I just want the value of the token. In VB.NET ;)

like image 940
Lars Holdgaard Avatar asked Dec 04 '25 22:12

Lars Holdgaard


1 Answers

Try this:

 Dim tokenJson = JsonConvert.SerializeObject(tokenJsonString)

 Dim jsonResult = JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(jsonString)
 Dim firstItem = jsonResult.Item("data").Item(0)

Cheers

like image 83
Luc Morin Avatar answered Dec 06 '25 13:12

Luc Morin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!