3

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 ;)

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

Comments

1

Example JSON :

{
  "fuits": [
    
  ],
  "vehicles": [
    {
      "cars": [
        {
          "skoda": "2Lacks",
          "maruti": 400000,
          "neon": "3 Lacks",
          
        },
        {
          
        }
      ]
    }
  }

If you want to acess the value for skoda in the above example json in VB.NET using JObject.Parse, Write it as :

Dim wallet As String = jsonobject("vehicles")(0)("cars")(0)("skoda").ToString()

Now you have 2Lacks in wallet!

Comments

0

Chosen awnser gives you the row { "token":"1edd6006-678a-4e6a-ab65-4fa60efa8632" } Had the same problem and to get exactly the value of the token you can do:

Dim firstItem = jsonResult.Item("data").Item(0).Value(Of String)("token")

Outputs: "1edd6006-678a-4e6a-ab65-4fa60efa8632"

Hope it helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.