<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Получить данные из Json строки]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=15249</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15249&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Получить данные из Json строки».]]></description>
		<lastBuildDate>Sat, 13 May 2023 22:19:47 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Получить данные из Json строки]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=158194#p158194</link>
			<description><![CDATA[<p><em></em></p>]]></description>
			<author><![CDATA[null@example.com (john_dease)]]></author>
			<pubDate>Sat, 13 May 2023 22:19:47 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=158194#p158194</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получить данные из Json строки]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=138590#p138590</link>
			<description><![CDATA[<p>Через RegEx.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Thu, 26 Mar 2020 09:47:06 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=138590#p138590</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получить данные из Json строки]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=138586#p138586</link>
			<description><![CDATA[<p>Так этот способ я знаю. А других нет?</p>]]></description>
			<author><![CDATA[null@example.com (svoboden)]]></author>
			<pubDate>Thu, 26 Mar 2020 03:46:59 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=138586#p138586</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получить данные из Json строки]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=138544#p138544</link>
			<description><![CDATA[<div class="codebox"><pre><code>json = {&quot;response&quot;:{&quot;text&quot;:&quot;Статус&quot;}}
jsObj := GetJS().Call(&quot;(&quot; json &quot;)&quot;)
MsgBox, % jsObj.response.text

GetJS() {
   static doc := ComObjCreate(&quot;htmlfile&quot;)
        , _ := doc.write(&quot;&lt;meta http-equiv=&quot;&quot;X-UA-Compatible&quot;&quot; content=&quot;&quot;IE=9&quot;&quot;&gt;&quot;)
        , JS := ObjBindMethod(doc.parentWindow, &quot;eval&quot;)
   Return JS
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Mon, 23 Mar 2020 06:21:20 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=138544#p138544</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Получить данные из Json строки]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=138543#p138543</link>
			<description><![CDATA[<p>Использую класс <a href="https://github.com/cocobelgica/AutoHotkey-JSON/">Json</a> для получения данных. В принципе, все работает, но можно ли короче получить вот эту запись ответа:<br /></p><div class="codebox"><pre><code>{&quot;response&quot;:{&quot;text&quot;:&quot;Статус&quot;}}</code></pre></div><p>Нужно изъять слово Статус.<br />Вот полная запись без токена и ид.<br />Получает статус группы вк:</p><div class="codebox"><pre><code>class JSON
{

    class Load extends JSON.Functor
    {
        Call(self, ByRef text, reviver:=&quot;&quot;)
        {
            this.rev := IsObject(reviver) ? reviver : false
            this.keys := this.rev ? {} : false

            static quot := Chr(34), bashq := &quot;\&quot; . quot
                 , json_value := quot . &quot;{[01234567890-tfn&quot;
                 , json_value_or_array_closing := quot . &quot;{[]01234567890-tfn&quot;
                 , object_key_or_object_closing := quot . &quot;}&quot;

            key := &quot;&quot;
            is_key := false
            root := {}
            stack := [root]
            next := json_value
            pos := 0

            while ((ch := SubStr(text, ++pos, 1)) != &quot;&quot;) {
                if InStr(&quot; `t`r`n&quot;, ch)
                    continue
                if !InStr(next, ch, 1)
                    this.ParseError(next, text, pos)

                holder := stack[1]
                is_array := holder.IsArray

                if InStr(&quot;,:&quot;, ch) {
                    next := (is_key := !is_array &amp;&amp; ch == &quot;,&quot;) ? quot : json_value

                } else if InStr(&quot;}]&quot;, ch) {
                    ObjRemoveAt(stack, 1)
                    next := stack[1]==root ? &quot;&quot; : stack[1].IsArray ? &quot;,]&quot; : &quot;,}&quot;

                } else {
                    if InStr(&quot;{[&quot;, ch) {
                        static json_array := Func(&quot;Array&quot;).IsBuiltIn || ![].IsArray ? {IsArray: true} : 0
                    
                        (ch == &quot;{&quot;)
                            ? ( is_key := true
                              , value := {}
                              , next := object_key_or_object_closing )
                        ; ch == &quot;[&quot;
                            : ( value := json_array ? new json_array : []
                              , next := json_value_or_array_closing )
                        
                        ObjInsertAt(stack, 1, value)

                        if (this.keys)
                            this.keys[value] := []
                    
                    } else {
                        if (ch == quot) {
                            i := pos
                            while (i := InStr(text, quot,, i+1)) {
                                value := StrReplace(SubStr(text, pos+1, i-pos-1), &quot;\\&quot;, &quot;\u005c&quot;)

                                static tail := A_AhkVersion&lt;&quot;2&quot; ? 0 : -1
                                if (SubStr(value, tail) != &quot;\&quot;)
                                    break
                            }

                            if (!i)
                                this.ParseError(&quot;&#039;&quot;, text, pos)

                              value := StrReplace(value,  &quot;\/&quot;,  &quot;/&quot;)
                            , value := StrReplace(value, bashq, quot)
                            , value := StrReplace(value,  &quot;\b&quot;, &quot;`b&quot;)
                            , value := StrReplace(value,  &quot;\f&quot;, &quot;`f&quot;)
                            , value := StrReplace(value,  &quot;\n&quot;, &quot;`n&quot;)
                            , value := StrReplace(value,  &quot;\r&quot;, &quot;`r&quot;)
                            , value := StrReplace(value,  &quot;\t&quot;, &quot;`t&quot;)

                            pos := i ; update pos
                            
                            i := 0
                            while (i := InStr(value, &quot;\&quot;,, i+1)) {
                                if !(SubStr(value, i+1, 1) == &quot;u&quot;)
                                    this.ParseError(&quot;\&quot;, text, pos - StrLen(SubStr(value, i+1)))

                                uffff := Abs(&quot;0x&quot; . SubStr(value, i+2, 4))
                                if (A_IsUnicode || uffff &lt; 0x100)
                                    value := SubStr(value, 1, i-1) . Chr(uffff) . SubStr(value, i+6)
                            }

                            if (is_key) {
                                key := value, next := &quot;:&quot;
                                continue
                            }
                        
                        } else {
                            value := SubStr(text, pos, i := RegExMatch(text, &quot;[\]\},\s]|$&quot;,, pos)-pos)

                            static number := &quot;number&quot;, integer :=&quot;integer&quot;
                            if value is %number%
                            {
                                if value is %integer%
                                    value += 0
                            }
                            else if (value == &quot;true&quot; || value == &quot;false&quot;)
                                value := %value% + 0
                            else if (value == &quot;null&quot;)
                                value := &quot;&quot;
                            else
                                this.ParseError(next, text, pos, i)

                            pos += i-1
                        }

                        next := holder==root ? &quot;&quot; : is_array ? &quot;,]&quot; : &quot;,}&quot;
                    } ; If InStr(&quot;{[&quot;, ch) { ... } else

                    is_array? key := ObjPush(holder, value) : holder[key] := value

                    if (this.keys &amp;&amp; this.keys.HasKey(holder))
                        this.keys[holder].Push(key)
                }
            
            } ; while ( ... )

            return this.rev ? this.Walk(root, &quot;&quot;) : root[&quot;&quot;]
        }

        ParseError(expect, ByRef text, pos, len:=1)
        {
            static quot := Chr(34), qurly := quot . &quot;}&quot;
            
            line := StrSplit(SubStr(text, 1, pos), &quot;`n&quot;, &quot;`r&quot;).Length()
            col := pos - InStr(text, &quot;`n&quot;,, -(StrLen(text)-pos+1))
            msg := Format(&quot;{1}`n`nLine:`t{2}`nCol:`t{3}`nChar:`t{4}&quot;
            ,     (expect == &quot;&quot;)     ? &quot;Extra data&quot;
                : (expect == &quot;&#039;&quot;)    ? &quot;Unterminated string starting at&quot;
                : (expect == &quot;\&quot;)    ? &quot;Invalid \escape&quot;
                : (expect == &quot;:&quot;)    ? &quot;Expecting &#039;:&#039; delimiter&quot;
                : (expect == quot)   ? &quot;Expecting object key enclosed in double quotes&quot;
                : (expect == qurly)  ? &quot;Expecting object key enclosed in double quotes or object closing &#039;}&#039;&quot;
                : (expect == &quot;,}&quot;)   ? &quot;Expecting &#039;,&#039; delimiter or object closing &#039;}&#039;&quot;
                : (expect == &quot;,]&quot;)   ? &quot;Expecting &#039;,&#039; delimiter or array closing &#039;]&#039;&quot;
                : InStr(expect, &quot;]&quot;) ? &quot;Expecting JSON value or array closing &#039;]&#039;&quot;
                :                      &quot;Expecting JSON value(string, number, true, false, null, object or array)&quot;
            , line, col, pos)

            static offset := A_AhkVersion&lt;&quot;2&quot; ? -3 : -4
            throw Exception(msg, offset, SubStr(text, pos, len))
        }

        Walk(holder, key)
        {
            value := holder[key]
            if IsObject(value) {
                for i, k in this.keys[value] {
                    ; check if ObjHasKey(value, k) ??
                    v := this.Walk(value, k)
                    if (v != JSON.Undefined)
                        value[k] := v
                    else
                        ObjDelete(value, k)
                }
            }
            
            return this.rev.Call(holder, key, value)
        }
    }

    class Dump extends JSON.Functor
    {
        Call(self, value, replacer:=&quot;&quot;, space:=&quot;&quot;)
        {
            this.rep := IsObject(replacer) ? replacer : &quot;&quot;

            this.gap := &quot;&quot;
            if (space) {
                static integer := &quot;integer&quot;
                if space is %integer%
                    Loop, % ((n := Abs(space))&gt;10 ? 10 : n)
                        this.gap .= &quot; &quot;
                else
                    this.gap := SubStr(space, 1, 10)

                this.indent := &quot;`n&quot;
            }

            return this.Str({&quot;&quot;: value}, &quot;&quot;)
        }

        Str(holder, key)
        {
            value := holder[key]

            if (this.rep)
                value := this.rep.Call(holder, key, ObjHasKey(holder, key) ? value : JSON.Undefined)

            if IsObject(value) {

                static type := A_AhkVersion&lt;&quot;2&quot; ? &quot;&quot; : Func(&quot;Type&quot;)
                if (type ? type.Call(value) == &quot;Object&quot; : ObjGetCapacity(value) != &quot;&quot;) {
                    if (this.gap) {
                        stepback := this.indent
                        this.indent .= this.gap
                    }

                    is_array := value.IsArray
                    if (!is_array) {
                        for i in value
                            is_array := i == A_Index
                        until !is_array
                    }

                    str := &quot;&quot;
                    if (is_array) {
                        Loop, % value.Length() {
                            if (this.gap)
                                str .= this.indent
                            
                            v := this.Str(value, A_Index)
                            str .= (v != &quot;&quot;) ? v . &quot;,&quot; : &quot;null,&quot;
                        }
                    } else {
                        colon := this.gap ? &quot;: &quot; : &quot;:&quot;
                        for k in value {
                            v := this.Str(value, k)
                            if (v != &quot;&quot;) {
                                if (this.gap)
                                    str .= this.indent

                                str .= this.Quote(k) . colon . v . &quot;,&quot;
                            }
                        }
                    }

                    if (str != &quot;&quot;) {
                        str := RTrim(str, &quot;,&quot;)
                        if (this.gap)
                            str .= stepback
                    }

                    if (this.gap)
                        this.indent := stepback

                    return is_array ? &quot;[&quot; . str . &quot;]&quot; : &quot;{&quot; . str . &quot;}&quot;
                }
            
            } else ; is_number ? value : &quot;value&quot;
                return ObjGetCapacity([value], 1)==&quot;&quot; ? value : this.Quote(value)
        }

        Quote(string)
        {
            static quot := Chr(34), bashq := &quot;\&quot; . quot

            if (string != &quot;&quot;) {
                  string := StrReplace(string,  &quot;\&quot;,  &quot;\\&quot;)
                ; , string := StrReplace(string,  &quot;/&quot;,  &quot;\/&quot;) ; optional in ECMAScript
                , string := StrReplace(string, quot, bashq)
                , string := StrReplace(string, &quot;`b&quot;,  &quot;\b&quot;)
                , string := StrReplace(string, &quot;`f&quot;,  &quot;\f&quot;)
                , string := StrReplace(string, &quot;`n&quot;,  &quot;\n&quot;)
                , string := StrReplace(string, &quot;`r&quot;,  &quot;\r&quot;)
                , string := StrReplace(string, &quot;`t&quot;,  &quot;\t&quot;)

                static rx_escapable := A_AhkVersion&lt;&quot;2&quot; ? &quot;O)[^\x20-\x7e]&quot; : &quot;[^\x20-\x7e]&quot;
                while RegExMatch(string, rx_escapable, m)
                    string := StrReplace(string, m.Value, Format(&quot;\u{1:04x}&quot;, Ord(m.Value)))
            }

            return quot . string . quot
        }
    }

    Undefined[]
    {
        get {
            static empty := {}, vt_empty := ComObject(0, &amp;empty, 1)
            return vt_empty
        }
    }

    class Functor
    {
        __Call(method, ByRef arg, args*)
        {
            if IsObject(method)
                return (new this).Call(method, arg, args*)
            else if (method == &quot;&quot;)
                return (new this).Call(arg, args*)
        }
    }
}

  HttpObj := ComObjCreate(&quot;WinHttp.WinHttpRequest.5.1&quot;)
   HttpObj.Open(&quot;POST&quot;, &quot;https://api.vk.com/method/status.get?user_id=-свой ид&amp;fields=bdate&amp;access_token=свой токен&amp;v=5.103&quot;, True)
    HttpObj.SetRequestHeader(&quot;User-Agent&quot;, &quot;Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36&quot;)
     HttpObj.SetRequestHeader(&quot;Content-Type&quot;,&quot;application/x-www-form-urlencoded&quot;)
     HttpObj.Send()
     HttpObj.WaitForResponse()
      Body := HttpObj.ResponseBody 
     pData := NumGet(ComObjValue(Body)+8+A_PtrSize) 
   json_str := StrGet(pData, Body.MaxIndex() + 1, &quot;utf-8&quot;) 

parsed := JSON.Load(json_str)

parsed_out := Format(&quot;
(Join`r`n
String: {}
Number: {}
Float:  {}
true:   {}
false:  {}
null:   {}
array:  [{}, {}, {}]
response: {{}json_str}&quot;&quot;{}&quot;&quot;{}}
)&quot;
, parsed.response.text)

var := parsed.response.text
Msgbox % var</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (svoboden)]]></author>
			<pubDate>Mon, 23 Mar 2020 05:09:54 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=138543#p138543</guid>
		</item>
	</channel>
</rss>
