Help with Json

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fbc
Posts: 11
Joined: 01 Aug 2021, 00:39

Help with Json

01 Aug 2021, 00:56

Hello, I'm needing help with a problem. I need the output of my switch to be AR or XY but it's always going to the default output "Error". However when I send

Code: Select all

MsgBox converted.data.address
it gives me the right anwser (AR or XY), i can't find out what it can be. I think it can be that txt isn't a string or it isn't getting the right value of the Json.
I know it would be a basic error that I'm doing but I can't find out what :(

Here's my code:

Code: Select all

    HTTP := ComObjCreate("MSXML2.XMLHTTP.6.0")
    HTTP.Open("GET", uri)
    HTTP.SetRequestHeader("Content-Type", "plain/text")
    HTTP.Send()
    result := HTTP.responseText
    converted := JSON.Load(result)
    txt := converted.data.address
    switch txt{
        case "XY":
            MsgBox, "XY"
        case "AR":
            MsgBox, "AR"
        default:
            MsgBox, "Error"
    }
User avatar
mikeyww
Posts: 26890
Joined: 09 Sep 2014, 18:38

Re: Help with Json

01 Aug 2021, 06:31

Your MsgBox example is obviously not the same code that you actually used. You can display the value of txt immediately after it is assigned. You can also copy it to the clipboard and paste it into the following Web site to see any invisible characters.

https://www.soscisurvey.de/tools/view-chars.php
Fbc
Posts: 11
Joined: 01 Aug 2021, 00:39

Re: Help with Json

01 Aug 2021, 08:31

Sorry I was trying to pass a clear code here and I don't posted my full code. But now I find out what was my problem.

I was trying to do a switch like this, with the or word to be 2 case:

Code: Select all

switch txt{
case "AR" or "Ra":
	MsgBox, "AR"
case "XY" or "YX":
	MsgBox, "XY"
default:
	MsgBox, "Error"
}
and my error is that switch doesn't need the "or" word. To work they need to be like this:

Code: Select all

switch txt{
case "AR", "Ra":
	MsgBox, "AR"
case "XY", "YX":
	MsgBox, "XY"
default:
	MsgBox, "Error"
}
Now it's working, Sorry but was a syntax error. And thank you for the help, this site will be helpfull in the future.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: cjsmile999, doodles333, Lamron750 and 346 guests