Display Multidimensional Array
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 33
- Joined: Sat Jan 15, 2011 10:57 am
Display Multidimensional Array
Hello all, I need some help with the display of the Keys and Subkeys of a nestet mutidimenional global array. On the OS X platform PLIST files become more and more important !
I would like to handle PLIST files correctly (not pharsing them) in many projects.
I just recently learned that there is a commandline utility (plutil) which converts PLIST files to JSON file format, Igor de Oliveira Couto has written a wonderfull library called EasyJSON wich converts JSON to an array and back.
If one now combines the two, we can convert a PLIST file with a shell call to a JSON file and then import it into the stack, the Library from Igor then converts the JSON to a multidimensional array. This all works beautifully, check the attached stack .
What I can not do - (and believe me I tried very hard for much to long ) is to display all the Keys and Subkeys as seen in the example of the stack !
I would like to be able to have them listet in this way:
gPlistArray["catalogs"]["5"]
gPlistArray["included manifests"]["1"]
gPlistArray["included manifests"]["2"]
etc.
so that I can copy and past them directly and work with them, also if I import complex PLISTS, I see all the Keys/Subkeys which are present.
Can anyone help ?
Cheers
Rolf
I would like to handle PLIST files correctly (not pharsing them) in many projects.
I just recently learned that there is a commandline utility (plutil) which converts PLIST files to JSON file format, Igor de Oliveira Couto has written a wonderfull library called EasyJSON wich converts JSON to an array and back.
If one now combines the two, we can convert a PLIST file with a shell call to a JSON file and then import it into the stack, the Library from Igor then converts the JSON to a multidimensional array. This all works beautifully, check the attached stack .
What I can not do - (and believe me I tried very hard for much to long ) is to display all the Keys and Subkeys as seen in the example of the stack !
I would like to be able to have them listet in this way:
gPlistArray["catalogs"]["5"]
gPlistArray["included manifests"]["1"]
gPlistArray["included manifests"]["2"]
etc.
so that I can copy and past them directly and work with them, also if I import complex PLISTS, I see all the Keys/Subkeys which are present.
Can anyone help ?
Cheers
Rolf
- Attachments
-
- Display Multidimensional Array.zip
- Display Multidimensional Array.zip
- (7.41 KiB) Downloaded 328 times
Last edited by Kangaroo SW on Wed Oct 02, 2013 7:14 am, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 9823
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Display Multidimensional Array
Apple's plist files are just XML. While translating them to JSON to later translate into an array, you could just use the revXML commands to parse them directly into an array.
As for the keys, you can get the keys of an array with "get the keys of tMyArray", looping through the results to display their associated values.
There may also be other solutions. What exactly are you aiming to do with those plist values?
As for the keys, you can get the keys of an array with "get the keys of tMyArray", looping through the results to display their associated values.
There may also be other solutions. What exactly are you aiming to do with those plist values?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Display Multidimensional Array
Hi.
Just a quick thought, check out the "element" keyword in the dictionary. Could be a clue there...
Craig Newman
Just a quick thought, check out the "element" keyword in the dictionary. Could be a clue there...
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 33
- Joined: Sat Jan 15, 2011 10:57 am
Re: Display Multidimensional Array
Hello Richard and Craig
Thanks for your answers !
I know that PLIST files are just XML files, but they must have a special structure, to my knowledge nobody has ever tried to pharse them with the built in XML tools, not evan RunRev has done it. They choose to have complete Apple PLISTS stored in fields (AppBuilder), they don't create them.
I do agree, the way I choose is a bit clumpsy but thats they way I would like to go !
Did you look at the stack attached (works only on OS X) there is a button which almost already does what I want, please check it out !
But unfortunately my scripting knowledge is not good enough to change the code so that I get the output which I like. I tried the last two
days - no go !
What do I use it for: Well there is a tool out there called Munki -> http://code.google.com/p/munki/wiki/Get ... dWithMunki its a software distribution tool for OS X. It uses PLIST files for software repositories etc. actually all over the place. I would like to make a GUI for this great tool but I need to read and write Apple PLIST files.
So if there is any Array Guru out there please have a look at my stack, its hard to explain in words.
Cheers
Rolf
Thanks for your answers !
I know that PLIST files are just XML files, but they must have a special structure, to my knowledge nobody has ever tried to pharse them with the built in XML tools, not evan RunRev has done it. They choose to have complete Apple PLISTS stored in fields (AppBuilder), they don't create them.
I do agree, the way I choose is a bit clumpsy but thats they way I would like to go !
Did you look at the stack attached (works only on OS X) there is a button which almost already does what I want, please check it out !
But unfortunately my scripting knowledge is not good enough to change the code so that I get the output which I like. I tried the last two
days - no go !
What do I use it for: Well there is a tool out there called Munki -> http://code.google.com/p/munki/wiki/Get ... dWithMunki its a software distribution tool for OS X. It uses PLIST files for software repositories etc. actually all over the place. I would like to make a GUI for this great tool but I need to read and write Apple PLIST files.
So if there is any Array Guru out there please have a look at my stack, its hard to explain in words.
Cheers
Rolf
-
- VIP Livecode Opensource Backer
- Posts: 56
- Joined: Sat Apr 08, 2006 5:28 pm
- Location: Eau Claire, WI
- Contact:
Re: Display Multidimensional Array
I use this function to dump a multidimensional array to text:
So if you had an array where "10" was in tArray["catalogs"]["count"] and 1 was in tArray["itemNum"], and you called:
you would get back:
You should be able to take this and tweak it for the format you need...
Code: Select all
function stsExamineArray pArray,pArrayName
if pArrayName = "" then
put "<root>" into pArrayName
put "==> NOTE: Passing name of array in 2nd param will replace <root> <=="&cr into tList
else
put "" into tList
end if
_stsGatherKeys pArray,pArrayName,tList
return tList
end stsExamineArray
on _stsGatherKeys pArray,pArrayName,@pList
repeat for each line tKey in (the keys of pArray)
put pArrayName & "[" & tKey & "]" into tParentName
if the keys of pArray[tKey] = "" then
-- no kids
put pArray[tKey] into tVal
replace CR with numToChar(11) in tVal
put tParentName && "=>" && tVal & cr after pList
end if
_stsGatherKeys pArray[tKey],tParentName,pList
end repeat
end _stsGatherKeys
Code: Select all
put stsExamineArray(tArray,"tArray")
- tArray[catalogs][count] => 10
tArray[itemNum] => 1
You should be able to take this and tweak it for the format you need...
Ken Ray
Sons of Thunder Software
Email: kray@sonsothunder.com
Web site: http://www.sonsothunder.com
Sons of Thunder Software
Email: kray@sonsothunder.com
Web site: http://www.sonsothunder.com
-
- VIP Livecode Opensource Backer
- Posts: 33
- Joined: Sat Jan 15, 2011 10:57 am
Re: Display Multidimensional Array (Solved)
Hello Ken
How do you say this in english You hit the nail on the head !!!!
Thank you so much for your function, it is exactly what I am looking for !
Cheers from Zurich
Rolf
How do you say this in english You hit the nail on the head !!!!
Thank you so much for your function, it is exactly what I am looking for !
Cheers from Zurich
Rolf