Page 3 of 3

Re: JSON library, write by cpp

Posted: 21 Aug 2023, 02:46
by 20170201225639
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

Re: JSON library, write by cpp

Posted: 21 Aug 2023, 03:38
by thqby
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

Re: JSON library, write by cpp

Posted: 21 Aug 2023, 05:58
by 20170201225639
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!

Re: JSON library, write by cpp

Posted: 03 Sep 2023, 20:15
by bonobo
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'])

Re: JSON library, write by cpp

Posted: 03 Sep 2023, 21:35
by thqby
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.

Re: JSON library, write by cpp

Posted: 03 Sep 2023, 21:54
by bonobo
Thanks for the clarification.

Re: JSON library, write by cpp

Posted: 09 Sep 2023, 07:57
by thqby
@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.

Re: JSON library, write by cpp

Posted: 10 Sep 2023, 00:24
by bonobo
Very nice. It's working perfectly now. Thanks for updating it.