JSON Problem

Get help with using AutoHotkey and its commands and hotkeys
Nisutec
Posts: 1
Joined: 31 May 2020, 08:08

JSON Problem

31 May 2020, 08:15

Hallo i have the following Autohotkey Script but why i can't convert the json string to an object ?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", "https api.test.net /status?key=a6c...",  Broken Link for safety true)
WebRequest.Send()
WebRequest.WaitForResponse()
Result := WebRequest.ResponseText
JSON := new JSON()
ResultJSON := JSON.Load(Result)
Test := IsObject(ResultJSON)
MsgBox % Test
The json string is this:

Code: Select all

{'success': True, 'session': {'online': False}}
teadrinker
Posts: 1630
Joined: 29 Mar 2015, 09:41
Contact:

Re: JSON Problem

31 May 2020, 12:01

The line JSON := new JSON() is unnecessary.
Nisutec wrote: The json string is this:

Code: Select all

{'success': True, 'session': {'online': False}}
AHK doesn't suport single quotes, you need to replace them with double. You can do it with StrReplace().
User avatar
Chunjee
Posts: 515
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: JSON Problem

31 May 2020, 13:15

msgbox the WebRequest.ResponseText and show what you are trying to parse. I suspect you will find an empty string or some other error.
User avatar
haichen
Posts: 461
Joined: 09 Feb 2014, 08:24

Re: JSON Problem

31 May 2020, 15:44

https://github.com/cocobelgica/AutoHotkey-JSON

Code: Select all

#include json.ahk
js ={"success": "Hello World","session": {"online": false	}}
test := JSON.Load(js)
msgbox, % test.success " "  test.session.online
results in "Hello World 0"

Return to “Ask For Help”

Who is online

Users browsing this forum: Ben, Fortran, Google [Bot], kdservices, ManualColdSwitch, Ploaie, vsub and 139 guests