objects: hierarchies: listing/comparing objects
Posted: 17 Dec 2017, 15:43
What are the best links currently, for listing all the keys in an object/checking if two objects match. That recurse through hierarchies. Thanks.
Let's help each other out
https://www.autohotkey.com/boards/
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=41510
Code: Select all
q:: ;object - list keys/values
;object example based on:
;GeekDude's tips and tricks - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=7&t=7190
;note: to make this work in AHK v2
;replace: (LTrim Join
;with: (LTrim Join Q
;http://www.json.org/example.html
oArray :=
(LTrim Join
{
"glossary":
{
"GlossDiv":
{
"GlossList":
{
"GlossEntry":
{
"Abbrev": "ISO 8879:1986",
"Acronym": "SGML",
"GlossDef":
{
"GlossSeeAlso":
[
"GML",
"XML"
],
"para": "A meta-markup language, used to create markup languages such as DocBook."
},
"GlossSee": "markup",
"GlossTerm": "Standard Generalized Markup Language",
"ID": "SGML",
"SortAs": "SGML"
}
},
"title": "S"
},
"title": "example glossary"
}
}
)
MsgBox, % Clipboard := JEE_ObjList(oArray)
oArray := ["a", "b", "c"]
MsgBox, % Clipboard := JEE_ObjList(oArray)
return
JEE_ObjList(oArray, vSep:=" ", vRecurse:=1)
{
if !vRecurse
{
for vKey, vValue in oArray
vOutput .= vKey vSep vValue "`r`n"
return SubStr(vOutput, 1, -2)
}
for vKey, vValue in oArray
{
;note: vRecurse is used to indicate depth, i.e. how many tabs to use
if IsObject(vValue)
vOutput .= JEE_StrRept("`t", vRecurse-1) vKey vSep "OBJECT`r`n" %A_ThisFunc%(vValue, vSep, vRecurse+1) "`r`n"
else
vOutput .= JEE_StrRept("`t", vRecurse-1) vKey vSep vValue "`r`n"
}
return SubStr(vOutput, 1, -2)
}
JEE_StrRept(vText, vNum)
{
if (vNum <= 0)
return
return StrReplace(Format("{:" vNum "}", ""), " ", vText)
;return StrReplace(Format("{:0" vNum "}", 0), 0, vText)
}
You can specify a max recursion depth. Also, you can look how HotKeyIt does in the link teadrinker (hello ) provided.how am I supposed to help users who do?