Deeksha_goyal
10 years agoContributor
Solved
Need to use " as aqstring.ListSeparator to get a value
Hi All,
i need to use " as list seperator, could you please help me how i can use it
string is like following and need to get toaken out of it
{"access_token":"JAQfNo9FH6kM1hLNyXxAsA","token_type":"BEARER","scope":"","expires_in":"3600"}
i need to use " as list seperator, could you please help me how i can use it
string is like following and need to get toaken out of it
{"access_token":"JAQfNo9FH6kM1hLNyXxAsA","token_type":"BEARER","scope":"","expires_in":"3600"}
- For simple cases you can use something like this:
Sub Main
Dim str, obj
str = "{""access_token"":""JAQfNo9FH6kM1hLNyXxAsA"",""token_type"":""BEARER"",""scope"":"""",""expires_in"":""3600""}"
Set obj = ParseJson(str)
Log.Message obj.access_token
Log.Message obj.token_type
Log.Message obj.scope
Log.Message obj.expires_in
End Sub
' Source: http://demon.tw/my-work/vbs-json.html
Function ParseJson(strJson)
Dim html, window
Set html = CreateObject("htmlfile")
Set window = html.parentWindow
window.execScript "var json = " & strJson, "JScript"
Set ParseJson = window.json
End Function
For arbitrary JSON, I'd recommend using a proper parser like .NET's JavaScriptSerializer class. To use JavaScriptSerializer, go to Tools > Current Project Properties > CLR Bridge, click Browse GAC and add the System.Web.Extensions assembly.
Sub Main
Dim str, parser, obj
str = "{""access_token"":""JAQfNo9FH6kM1hLNyXxAsA"",""token_type"":""BEARER"",""scope"":"""",""expires_in"":""3600""}"
Set parser = dotNET.System_Web_Script_Serialization.JavaScriptSerializer.zctor
Set obj = parser.Deserialize_2(str, dotNET.System.Object.zctor.GetType)
Log.Message obj.Item("access_token").OleValue
Log.Message obj.Item("token_type").OleValue
Log.Message obj.Item("scope").OleValue
Log.Message obj.Item("expires_in").OleValue
End Sub