dpskipper dpskipper - 9 months ago 46
Vb.net Question

Parsing the output of a API call, VB.net

I call an API in Visual Basic and it returns me this:

"access_token": "21652337f6733aec846eecd28bc421642a040ed68fd288bb2e1b96a3fa3",
"token_type": "bearer",
"expires_in": 7776000,
"created_at": 1471158248

I can save this response to a variable, but how do I filter out everything but the Access Token and then save that to a variable?


Public Function GetAccessToken(input As String) As String
    Dim result = System.Text.RegularExpressions.Regex.Match(input, """access_token"":\s*""([^""]*)""")
    If result.Success Then
        Return result.Groups(1).Value
    End If
    Return ""
End Function