v2 object issues Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Gate
Posts: 27
Joined: 31 Jan 2021, 20:00

v2 object issues

25 Aug 2023, 20:48

In my http request to access an important API, I need to send in a JSON object with header: { x-api-key : "myapikey"}

I've always built the object in AHK first and then parsed it into JSON with a function.

New AHKv2 decided that 'x-api-key' is an 'Invalid property name in object literal'.

Come on... that's crazy. I need to be able to make an object with a '-' in the key name. Can this be fixed or will I be forever using AHK v1?



I'm doing everything I can to make a workaround... still no luck... It's giving me errors that make zero sense.

Error: This value of type "Object" has no property named "__Item".

003: p := {}
▶ 004: p["x-api-key"] := 1
006: MsgBox(p["x-api-key"])
008: ExitApp()
Gate
Posts: 27
Joined: 31 Jan 2021, 20:00

Re: v2 object issues

25 Aug 2023, 20:58

If there's no fix, can this be moved to AHK v2 bugs. This is serious. I can't use v2 until this is fixed.

It's frustrating to run into an error like this after spending 20hrs learning the new system and rewriting key functions in the new syntax, only to find I can't use any of this for my primary use case because of some overly strict syntax requirements.
20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

Re: v2 object issues  Topic is solved

25 Aug 2023, 21:26

Use Map (see: https://www.autohotkey.com/docs/v2/v2-changes.htm#objects-misc)

Code: Select all

p := Map()
p["x-api-key"] := 1
006: MsgBox(p["x-api-key"])
008: ExitApp()
Gate
Posts: 27
Joined: 31 Jan 2021, 20:00

Re: v2 object issues

25 Aug 2023, 21:49

Okay the workaround for map is working thanks. It's too bad I can't use the regular object notation though { k : v }, I'm going to have to rewrite a bunch of code.
20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

Re: v2 object issues

25 Aug 2023, 22:32

Yes, this is a big part of the process of converting from v1 to v2. But IMO it's worth it. It makes the code less prone to breaking.

For previous discussions see viewtopic.php?t=67213&start=40

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: emp00, WarlordAkamu67 and 44 guests