I have the following json return from the url:
{"token_type":"Bearer","expires_in":"3599","expires_on":"1433956297","not_before":"1433952397","resource":"https://outlook.office365.com/","access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSIsImtpZCI6Ik1uQ19WWmNBVGZNNXBPWWlKSE1iYTlnb0VLWSJ9.eyJhdWQi????...."
I want to extract the access_token
in ASP.NET VB, but no matter what I try, it generates error. What is the the best solution to do this?
This is my code:
Dim parsedObject = JObject.Parse(<json string>)
Dim docs = parsedObject("access_token")
For Each doc In docs
Dim snippet As String = doc("access_token")
Next
label1.text = snippet
Your variable snippet is not accessible outside the loop: you can't access it outside of the loop.
Step thru your debugger: you need to figure out what the value and data type of docs are before you go any further. Since you're already referring to the value of "access_token" from docs, you probably can't get it again from the resultant value. I'm guessing it should just give you a string; it's hard to say without the error.