Search through nested arrays
Posted: Sun Dec 03, 2017 5:42 pm
Hi all,
I've struggled to work this one out and finally need to turn to the community for help. I have a repeating array with many nested arrays (all fake data btw), where I want to extract the firstnames, lastnames and nhs number. The tricky part is that the nhs number is sometimes under the first nested array of [partyAddtionalInfo] and sometimes under the second.
My attempt, which works feels a bit clunky.
I was reading through this example (http://lessons.livecode.com/m/4071/l/21 ... dable-form) and I can almost 'sense' a better way, using a function which calls itself, but I can't quite figure it out.
I could leave my solution as is, but I'm keen to understand any better ways.

I've struggled to work this one out and finally need to turn to the community for help. I have a repeating array with many nested arrays (all fake data btw), where I want to extract the firstnames, lastnames and nhs number. The tricky part is that the nhs number is sometimes under the first nested array of [partyAddtionalInfo] and sometimes under the second.
My attempt, which works feels a bit clunky.
Code: Select all
repeat for each Key temp in tParties
repeat for each Key temp2 in tParties[temp][partyAdditionalInfo]
repeat for each key temp3 in tParties[temp][partyAdditionalInfo][temp2]
if tParties[temp][partyAdditionalInfo][temp2][temp3] is "uk.nhs.nhs_number" then
put tParties[temp][partyAdditionalInfo][temp2]["value"] into tNHSNumber
end if
end repeat
end repeat
put tNHSNumber && tParties[temp][firstNames] && tParties[temp][lastNames] & cr after tPatientList
end repeat
I could leave my solution as is, but I'm keen to understand any better ways.
