<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Помогите переписать JSON_Stringify]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=16323&amp;type=atom" />
	<updated>2021-06-06T00:31:41Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=16323</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148302#p148302" />
			<content type="html"><![CDATA[<p>Здесь просто пустые строки убираются.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-06-06T00:31:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148302#p148302</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148300#p148300" />
			<content type="html"><![CDATA[<p>Огромное спасибо. Регулярные выражения сила, правда ничего не понимаю именно в таких. Слишком сложно выглядит.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-06-05T23:19:29Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148300#p148300</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148298#p148298" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>msgbox, % JSON.Stringify([{&quot;test&quot;: 1}], &quot;`t&quot;)

class JSON
{
	Stringify(value, space := 0, _indent := 1)
	{
		_space := space
		if (space ~= &quot;^\d+$&quot;)
		{
			_space := strRepeat(A_Space, space)
		}

		str := &quot;&quot;
		array := true
		for k in value
		{
			if (k == A_Index)
			{
				continue
			}

			array := false
			break
		}

		indent := _indent
		for a, b in value
		{
			if (space)
			{
				str .= strRepeat(_space, indent)
			}

			str .= (array ? &quot;&quot; : &quot;&quot;&quot;&quot; a &quot;&quot;&quot;: &quot;)

			if (IsObject(b))
			{
				if (space)
				{
					str := RTrim(str, &quot; &quot;) &quot;`n&quot; strRepeat(_space, indent)
				}

				str .= this.Stringify(b, space, indent + 1)
			}
			else
			{
				str .= &quot;&quot;&quot;&quot; StrReplace(b, &quot;&quot;&quot;&quot;, &quot;\&quot;&quot;&quot;) &quot;&quot;&quot;&quot;
			}

			str .= &quot;,&quot; (space ? &quot;`n&quot; : &quot; &quot;)
		}
		str := RTrim(str, &quot; ,`n&quot;)
		str := RegExReplace(str, &quot;`n([\s]+)?`n&quot;, &quot;`n&quot;)

		indent--
		out := (array ? &quot;[&quot; : &quot;{&quot;) (space ? &quot;`n&quot; : &quot;&quot;) str (space ? &quot;`n&quot; : &quot;&quot;)
		out .= (space ? strRepeat(_space, indent) : &quot;&quot;) (array ? &quot;]&quot; : &quot;}&quot;)
		return RegExReplace(out, &quot;^(\h*(\R|$))+|\R\h*(?=\R|$)&quot;)
	}
}

strRepeat(str, count)
{
	return StrReplace(Format(&quot;{:&quot; count &quot;}&quot;, &quot;&quot;), &quot; &quot;, str)
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-06-05T19:50:37Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148298#p148298</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148297#p148297" />
			<content type="html"><![CDATA[<p>С данным классом тоже были проблемы.. Вроде значения грузились или сохранялись как-то не правильно.<br />Давайте попробуем исправить изначальный код?</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-06-05T15:54:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148297#p148297</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148296#p148296" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>obj := [{test: 1}]
MsgBox, % JSON.Dump(obj,, &quot;`t&quot;)

class JSON
{
	/**
	 * Method: Load
	 *     Parses a JSON string into an AHK value
	 * Syntax:
	 *     value := JSON.Load( text [, reviver ] )
	 * Parameter(s):
	 *     value      [retval] - parsed value
	 *     text    [in, ByRef] - JSON formatted string
	 *     reviver   [in, opt] - function object, similar to JavaScript&#039;s
	 *                           JSON.parse() &#039;reviver&#039; parameter
	 */
	class Load extends JSON.Functor
	{
		Call(self, ByRef text, reviver:=&quot;&quot;)
		{
			this.rev := IsObject(reviver) ? reviver : false
		; Object keys(and array indices) are temporarily stored in arrays so that
		; we can enumerate them in the order they appear in the document/text instead
		; of alphabetically. Skip if no reviver function is specified.
			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) {
					; Check if Array() is overridden and if its return value has
					; the &#039;IsArray&#039; property. If so, Array() will be called normally,
					; otherwise, use a custom base object for arrays
						static json_array := Func(&quot;Array&quot;).IsBuiltIn || ![].IsArray ? {IsArray: true} : 0
					
					; sacrifice readability for minor(actually negligible) performance gain
						(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
							; we can do more here to pinpoint the actual culprit
							; but that&#039;s just too much extra work.
								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)
		}
	}

	/**
	 * Method: Dump
	 *     Converts an AHK value into a JSON string
	 * Syntax:
	 *     str := JSON.Dump( value [, replacer, space ] )
	 * Parameter(s):
	 *     str        [retval] - JSON representation of an AHK value
	 *     value          [in] - any value(object, string, number)
	 *     replacer  [in, opt] - function object, similar to JavaScript&#039;s
	 *                           JSON.stringify() &#039;replacer&#039; parameter
	 *     space     [in, opt] - similar to JavaScript&#039;s JSON.stringify()
	 *                           &#039;space&#039; parameter
	 */
	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) {
			; Check object type, skip serialization for other object types such as
			; ComObject, Func, BoundFunc, FileObject, RegExMatchObject, Property, etc.
				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
				; Array() is not overridden, rollback to old method of
				; identifying array-like objects. Due to the use of a for-loop
				; sparse arrays such as &#039;[1,,3]&#039; are detected as objects({}). 
					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
		}
	}

	/**
	 * Property: Undefined
	 *     Proxy for &#039;undefined&#039; type
	 * Syntax:
	 *     undefined := JSON.Undefined
	 * Remarks:
	 *     For use with reviver and replacer functions since AutoHotkey does not
	 *     have an &#039;undefined&#039; type. Returning blank(&quot;&quot;) or 0 won&#039;t work since these
	 *     can&#039;t be distnguished from actual JSON values. This leaves us with objects.
	 *     Replacer() - the caller may return a non-serializable AHK objects such as
	 *     ComObject, Func, BoundFunc, FileObject, RegExMatchObject, and Property to
	 *     mimic the behavior of returning &#039;undefined&#039; in JavaScript but for the sake
	 *     of code readability and convenience, it&#039;s better to do &#039;return JSON.Undefined&#039;.
	 *     Internally, the property returns a ComObject with the variant type of VT_EMPTY.
	 */
	Undefined[]
	{
		get {
			static empty := {}, vt_empty := ComObject(0, &amp;empty, 1)
			return vt_empty
		}
	}

	class Functor
	{
		__Call(method, ByRef arg, args*)
		{
		; When casting to Call(), use a new instance of the &quot;function object&quot;
		; so as to avoid directly storing the properties(used across sub-methods)
		; into the &quot;function object&quot; itself.
			if IsObject(method)
				return (new this).Call(method, arg, args*)
			else if (method == &quot;&quot;)
				return (new this).Call(arg, args*)
		}
	}
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-06-05T15:47:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148296#p148296</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148295#p148295" />
			<content type="html"><![CDATA[<p>Можно без &quot;htmlfile&quot;? Он мне приносил сюрпризы какие-то, о которых сейчас не вспомню. Но не хотелось бы натолкнуться на них еще раз.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-06-05T15:40:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148295#p148295</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148293#p148293" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>json := [{test: 1}]
MsgBox, % AhkToJSON(json, &quot;`t&quot;)

AhkToJSON(obj, indent := &quot;&quot;) {
   static Doc, JS
   if !Doc {
      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 := Doc.parentWindow
      ( Doc.documentMode &lt; 9 &amp;&amp; JS.execScript() )
   }
   if indent|1 {
      if IsObject( obj ) {
         isArray := true
         for key in obj {
            if IsObject(key)
               throw Exception(&quot;Invalid key&quot;)
            if !( key = A_Index || isArray := false )
               break
         }
         for k, v in obj
            str .= ( A_Index = 1 ? &quot;&quot; : &quot;,&quot; ) . ( isArray ? &quot;&quot; : &quot;&quot;&quot;&quot; . k . &quot;&quot;&quot;:&quot; ) . %A_ThisFunc%(v, true)

         Return isArray ? &quot;[&quot; str &quot;]&quot; : &quot;{&quot; str &quot;}&quot;
      }
      else if !(obj*1 = &quot;&quot; || RegExMatch(obj, &quot;^-?0|\s&quot;))
         Return obj
      
      for k, v in [[&quot;\&quot;, &quot;\\&quot;], [A_Tab, &quot;\t&quot;], [&quot;&quot;&quot;&quot;, &quot;\&quot;&quot;&quot;], [&quot;/&quot;, &quot;\/&quot;], [&quot;`n&quot;, &quot;\n&quot;], [&quot;`r&quot;, &quot;\r&quot;], [Chr(12), &quot;\f&quot;], [Chr(8), &quot;\b&quot;]]
         obj := StrReplace( obj, v[1], v[2] )

      Return &quot;&quot;&quot;&quot; obj &quot;&quot;&quot;&quot;
   }
   sObj := %A_ThisFunc%(obj, true)
   Return JS.eval(&quot;JSON.stringify(&quot; . sObj . &quot;,&#039;&#039;,&#039;&quot; . indent . &quot;&#039;)&quot;)
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-06-05T15:29:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148293#p148293</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148291#p148291" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>А в чём разница между первым и вторым?</p></blockquote></div><p>Пустая строка после &quot;[&quot;.<br /></p><div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><p>И зачем 1 в кавычках?</p></blockquote></div><p>Кхм.. Оно любое значение берет в кавычки.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-06-05T12:44:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148291#p148291</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148289#p148289" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>Превращается в:<br />А ожидается:</p></blockquote></div><p>А в чём разница между первым и вторым? Я не вижу. И зачем 1 в кавычках?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-06-05T12:24:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148289#p148289</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148288#p148288" />
			<content type="html"><![CDATA[<p>Нашел ошибку, при которой:<br /></p><div class="codebox"><pre><code>[{test: 1}]</code></pre></div><p>Превращается в:<br /></p><div class="codebox"><pre><code>
[

	{
		&quot;test&quot;: &quot;1&quot;
	}
]
</code></pre></div><p>А ожидается:<br /></p><div class="codebox"><pre><code>
[
	{
		&quot;test&quot;: &quot;1&quot;
	}
]
</code></pre></div><p>Использование:<br /></p><div class="codebox"><pre><code>msgbox, % JSON.Stringify([{&quot;test&quot;: 1}], &quot;`t&quot;)</code></pre></div><div class="codebox"><pre><code>class JSON
{
	Stringify(value, space := 0, _indent := 1)
	{
		_space := space
		if (space ~= &quot;^\d+$&quot;)
		{
			_space := strRepeat(A_Space, space)
		}

		str := &quot;&quot;
		array := true
		for k in value
		{
			if (k == A_Index)
			{
				continue
			}

			array := false
			break
		}

		indent := _indent
		for a, b in value
		{
			if (space)
			{
				str .= strRepeat(_space, indent)
			}

			str .= (array ? &quot;&quot; : &quot;&quot;&quot;&quot; a &quot;&quot;&quot;: &quot;)

			if (IsObject(b))
			{
				if (space)
				{
					str := RTrim(str, &quot; &quot;) &quot;`n&quot; strRepeat(_space, indent)
				}

				str .= this.Stringify(b, space, indent + 1)
			}
			else
			{
				str .= &quot;&quot;&quot;&quot; StrReplace(b, &quot;&quot;&quot;&quot;, &quot;\&quot;&quot;&quot;) &quot;&quot;&quot;&quot;
			}

			str .= &quot;,&quot; (space ? &quot;`n&quot; : &quot; &quot;)
		}
		str := RTrim(str, &quot; ,`n&quot;)
		str := RegExReplace(str, &quot;`n([\s]+)?`n&quot;, &quot;`n&quot;)

		indent--
		out := (array ? &quot;[&quot; : &quot;{&quot;) (space ? &quot;`n&quot; : &quot;&quot;) str (space ? &quot;`n&quot; : &quot;&quot;)
		out .= (space ? strRepeat(_space, indent) : &quot;&quot;) (array ? &quot;]&quot; : &quot;}&quot;)
		return out
	}
}

strRepeat(str, count)
{
	return StrReplace(Format(&quot;{:&quot; count &quot;}&quot;, &quot;&quot;), &quot; &quot;, str)
}</code></pre></div><p>Помогите исправить.</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-06-05T09:54:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148288#p148288</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147704#p147704" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>На теги &quot;code&quot; форум ругается, а на спойлеры нет? Багуля))</p></blockquote></div><p>Да, известный баг со спойлерами.</p>]]></content>
			<author>
				<name><![CDATA[ypppu]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5974</uri>
			</author>
			<updated>2021-05-06T15:15:23Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147704#p147704</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147703#p147703" />
			<content type="html"><![CDATA[<p>К сожалению частые проекты все еще связаны с игрой, где используется ANSI кодировка + компилятор сделан на ANSI (+ заморозил себя на 1.1.25 версии ахк).</p><p>OFF: Я похоже сломал верстку чем-то, но не понимаю чем.. Спойлер в спойлере?<br />UPD OFF: Спойлер не закрыл.. На теги &quot;code&quot; форум ругается, а на спойлеры нет? Багуля))</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-05-06T15:02:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147703#p147703</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147702#p147702" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Phoenixxx_Czar пишет:</cite><blockquote><p>У меня все скрипты скомпилированы в Ansi-32, все будет хорошо?</p></blockquote></div><p>Не знаю, ANSI сохранён только из соображений обратной совместимости. Отсюда и проблемы с русскими буквами. Сейчас нормальный вариант — это Unicode.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-06T14:50:48Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147702#p147702</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147701#p147701" />
			<content type="html"><![CDATA[<p>У меня все скрипты скомпилированы в Ansi-32, все будет хорошо?<br />Хотя глупый вопрос, я этот класс использую долгое время ибо тот что на форуме, ломает вроде русские буквы, а другой какой-то вариант ломал данные (не знаю почему). По этому и остановился на этом варианте.</p><p>UPD:<br />Что-то страшно мне стало использовать вариант с htmlfile.. Судя из прошлого моего. Похоже придется вернуться к изначальному варианту..</p>]]></content>
			<author>
				<name><![CDATA[Phoenixxx_Czar]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34426</uri>
			</author>
			<updated>2021-05-06T14:00:55Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147701#p147701</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Помогите переписать JSON_Stringify]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147700#p147700" />
			<content type="html"><![CDATA[<p>ScriptControl есть только в 32-битном исполнении, не будет работать на AHK 64-bit.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-05-06T13:36:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147700#p147700</id>
		</entry>
</feed>
