Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Ask for Help (v2) • Re: parse json into submenu and sub-sub menus in v2

$
0
0
Thank you!! i was now able to compile successfully after using the new library that you gave and then win + n menu doesn't show up at all.

attached Code , json.ahk and actual json


CODE:


#include C:\hotkey\json.ahk

; Read the JSON file
jsonContent := FileRead("C:\hotkey\myjson1.json")

; Parse the JSON content
jsonObj := JSON.Load(jsonContent)

m := Menu()

objToMenu(jsonObj, m)

objToMenu(obj, menuObj?) {
if !IsSet(menuObj)
menuObj := Menu()
for itemName, menuItem in (obj is Array ? obj : obj.OwnProps()) {
if IsObject(menuItem) {
menuObj.Add(itemName, objToMenu(menuItem))
} else {
menuObj.Add(menuItem, MenuHandler)
}
}
return menuObj

MenuHandler(item, *) {
A_Clipboard := item
Send('^v')
}
}

; Hotkey to show the menu
#n::m.Show() ; i.e. press the Win-N hotkey to show the menu.




image.png


image.png




{
"Mainmenu1": {
"What is the Queston 1": [
"The answer can be anything -it --rm aks-ssh --especially blah <> --image"
],
"can you type this": [
"yes i can type \"anything\" you want me to",
"i can also write anything that is gibberish"
],
"Good Morning": [
"very good morning",
"morning is ok -- with so many ideas like , :' and also anything ",
"Thank you"
]
},
"Mainmenu2": {
"Random Query": [
"Some random command -it --rm --image=randomimage:latest"
],
"Lorem Ipsum": [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"
],
"Gibberish Text": [
"Flibber flabber blibber blabber",
"Blah blah blah -- with symbols like @#$%&*()!",
"Thank you for using gibberish"
]
}
}

Statistics: Posted by sanneedshelp — 56 minutes ago



Viewing all articles
Browse latest Browse all 579

Trending Articles