<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK v2: JSON: кто как десериализует]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=18483</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=18483&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK v2: JSON: кто как десериализует».]]></description>
		<lastBuildDate>Sat, 30 Aug 2025 03:33:54 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK v2: JSON: кто как десериализует]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162649#p162649</link>
			<description><![CDATA[<p>Спасибо.</p>]]></description>
			<author><![CDATA[null@example.com (haridev)]]></author>
			<pubDate>Sat, 30 Aug 2025 03:33:54 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162649#p162649</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK v2: JSON: кто как десериализует]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162648#p162648</link>
			<description><![CDATA[<p>Для v2:<br /></p><div class="codebox"><pre><code>#Requires AutoHotkey v2

json := &#039;{&quot;key&quot;: &quot;value&quot;}&#039;
obj := LightJson.Parse(json)
MsgBox obj[&#039;key&#039;]
MsgBox LightJson.Stringify(obj)
MsgBox LightJson.Beautify(json, &#039;    &#039;)

class LightJson
{
    static JS := LightJson.GetJS(), true := {}, false := {}, null := {}

    static Parse(json, objIsMap := true, _rec?) {
        if !IsSet(_rec)
            obj := this.Parse(this.JS.JSON.parse(json), objIsMap, true)
        else if !IsObject(json)
            obj := json
        else if this.JS.Object.prototype.toString.call(json) == &#039;[object Array]&#039; {
            obj := []
            Loop json.length
                obj.Push(this.Parse(json.%A_Index - 1%, objIsMap, true))
        }
        else {
            obj := objIsMap ? Map() : {}
            keys := this.JS.Object.keys(json)
            Loop keys.length {
                k := keys.%A_Index - 1%
                ( objIsMap &amp;&amp; obj[k]  := this.Parse(json.%k%, true , true))
                (!objIsMap &amp;&amp; obj.%k% := this.Parse(json.%k%, false, true))
            }
        }
        return obj
    }

    static Stringify(obj, indent := &#039;&#039;) {
        if indent = true {
            for k, v in [&#039;true&#039;, &#039;false&#039;, &#039;null&#039;]
                if (obj = this.%v%)
                    return v

            if IsObject(obj) {
                isArray := Type(obj) = &#039;Array&#039;
                enumerable := Type(obj) = &#039;Object&#039; ? obj.OwnProps() : obj
                str := &#039;&#039;
                for k, v in enumerable
                    str .= (A_Index = 1 ? &#039;&#039; : &#039;,&#039;) . (isArray ? &#039;&#039; : this.Stringify(k, true) . &#039;:&#039;) . this.Stringify(v, true)

                return isArray ? &#039;[&#039; str &#039;]&#039; : &#039;{&#039; str &#039;}&#039;
            }
            if IsNumber(obj) &amp;&amp; Type(obj) != &#039;String&#039;
                return obj

            for k, v in [[&#039;\&#039;, &#039;\\&#039;], [A_Tab, &#039;\t&#039;], [&#039;&quot;&#039;, &#039;\&quot;&#039;], [&#039;/&#039;, &#039;\/&#039;], [&#039;`n&#039;, &#039;\n&#039;], [&#039;`r&#039;, &#039;\r&#039;], [Chr(12), &#039;\f&#039;], [Chr(8), &#039;\b&#039;]]
                obj := StrReplace(obj, v[1], v[2])

            return &#039;&quot;&#039; obj &#039;&quot;&#039;
        }
        sObj := this.Stringify(obj, true)
        return this.JS.eval(&#039;JSON.stringify(&#039; . sObj . &#039;,&quot;&quot;,&quot;&#039; . indent . &#039;&quot;)&#039;)
    }

    static Beautify(json, indent) =&gt; this.JS.eval(&#039;JSON.stringify(&#039; . json . &#039;,&quot;&quot;,&quot;&#039; . indent . &#039;&quot;)&#039;)

    static GetJS() {
        static document := &#039;&#039;, JS
        if !document {
            document := ComObject(&#039;HTMLFILE&#039;)
            document.write(&#039;&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=9&quot;&gt;&#039;)
            JS := document.parentWindow
            (document.documentMode &lt; 9 &amp;&amp; JS.execScript())
        }
        return JS
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 29 Aug 2025 21:19:21 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162648#p162648</guid>
		</item>
		<item>
			<title><![CDATA[AHK v2: JSON: кто как десериализует]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162647#p162647</link>
			<description><![CDATA[<p>В коллекции есть вариант для AHK v1, но я затруднился перевести его на v2.</p>]]></description>
			<author><![CDATA[null@example.com (haridev)]]></author>
			<pubDate>Fri, 29 Aug 2025 17:36:04 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162647#p162647</guid>
		</item>
	</channel>
</rss>
