JSON library, write by cpp

Post your working scripts, libraries and tools.
20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

Re: JSON library, write by cpp

21 Aug 2023, 02:46

Would it be possible to make JSON.parse(...) accept plain quoted JSON strings as arguments?

Currently when e.g. using Webview2 to get the returned innerHTML of a DOM node, doing something like this is needed:

Code: Select all

wv2core.ExecuteScript("ele.innerHTML", WebView2.Handler(getInnerHTML))

getInnerHTML(handler, errorCode, resultObjectAsJson)
{
    K_Show(JSON.parse("[" . StrGet(resultObjectAsJson) . "]")[1]) ; 👈
}
It's not a big deal by any means, but I believe technically quoted strings can be valid JSON. For reference:
JSON can actually take the form of any data type that is valid for inclusion inside JSON, not just arrays or objects. So for example, a single string or number would be valid JSON.
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON
User avatar
thqby
Posts: 427
Joined: 16 Apr 2021, 11:18
Contact:

Re: JSON library, write by cpp

21 Aug 2023, 03:38

This library is taken from the JSON section of ahk_h, and the latest version of the source code already supports JSON5 and non object type literals.

https://github.com/thqby/AutoHotkey_H/blob/alpha/source/script_h.cpp#L2846
20170201225639
Posts: 144
Joined: 01 Feb 2017, 22:57

Re: JSON library, write by cpp

21 Aug 2023, 05:58

thqby wrote:
21 Aug 2023, 03:38
This library is taken from the JSON section of ahk_h, and the latest version of the source code already supports JSON5 and non object type literals.

https://github.com/thqby/AutoHotkey_H/blob/alpha/source/script_h.cpp#L2846
Sounds great. Look forward to when it's ported over!
bonobo
Posts: 76
Joined: 03 Sep 2023, 20:13

Re: JSON library, write by cpp

03 Sep 2023, 20:15

On my machine the latest alpha-3 throws an error ("invalid memory read/write") over this line used for initialization.

Code: Select all

Native.LoadModule('Lib\ahk-json\' (A_PtrSize * 8) 'bit\ahk-json.dll', ['JSON'])
User avatar
thqby
Posts: 427
Joined: 16 Apr 2021, 11:18
Contact:

Re: JSON library, write by cpp

03 Sep 2023, 21:35

after v2.1-alpha.3, the memory layout of the object has changed, so the current version of the library is not compatible with the new version.
bonobo
Posts: 76
Joined: 03 Sep 2023, 20:13

Re: JSON library, write by cpp

03 Sep 2023, 21:54

Thanks for the clarification.
User avatar
thqby
Posts: 427
Joined: 16 Apr 2021, 11:18
Contact:

Re: JSON library, write by cpp

09 Sep 2023, 07:57

@bonobo
A version supporting v2.1 has been uploaded. You also need to update the Native.ahk library.

@20170201225639
ahk2-json for v2.1, added support for string and numeric types.
bonobo
Posts: 76
Joined: 03 Sep 2023, 20:13

Re: JSON library, write by cpp

10 Sep 2023, 00:24

Very nice. It's working perfectly now. Thanks for updating it.

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 17 guests