Code: Select all
var:="{key1: {a:[1,0], b:[1,0]}, key2: [1,0], key3: [1,0]}"
Code: Select all
var:="{key1: {a:[1,0], b:[1,0]}, key2: [1,0], key3: [1,0]}"
Code: Select all
var:="{key1: {a:[1,0], b:[1,0]}, key2: [1,0], key3: [1,0]}"
if !myarray {
FileRead, ScriptText, myscript.ahk
FileDelete, myscript.ahk
FileAppend, % "myarray := " var "`n" ScriptText, myscript.ahk
MsgBox, about to reload ; to prevent potential runaway script
Reload
}
MsgBox, % myarray.key1.a.1
Code: Select all
var:="{key1: {a:[1,0], b:[1,0]}, key2: [1,0], key3: [1,0]}"
obj := JsonToAHK(var)
MsgBox, % obj.key2.1
JsonToAHK(json, rec := false) {
static doc := ComObjCreate("htmlfile")
, __ := doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
, JS := doc.parentWindow
if !rec
obj := %A_ThisFunc%(JS.eval("(" . json . ")"), true)
else if !IsObject(json)
obj := json
else if JS.Object.prototype.toString.call(json) == "[object Array]" {
obj := []
Loop % json.length
obj.Push( %A_ThisFunc%(json[A_Index - 1], true) )
}
else {
obj := {}
keys := JS.Object.keys(json)
Loop % keys.length {
k := keys[A_Index - 1]
obj[k] := %A_ThisFunc%(json[k], true)
}
}
Return obj
}