On Jan 6, 2017, at 8:28 PM, David Adams wrote: > I've got a bunch of objects with the same format. > > I can put them into an ARRAY OBJECT or as elements within a single object. > > I can't really see what in the language supports finding in either of these > cases. Find in array doesn't have any mention of how it works with object > arrays, there's nothing in the KB. > > Likewise, I'm not clear how to do a find for a key-value pair nested inside > of a big object in 4D. > > In this case, I won't be using the object component (absolutely nothing > against it - I'm just keen to do this from scratch at the moment.) > > This seems like a really remedial question, so I probably should have > posted it under an assumed identity ;-) No, I've been stuck in V13 for ages > and using NTK JSON for object-like structures. Now I'm going in for V15/V16 > and I'm very pleased with C_OBJECT so far. I'm impressed at how > unexpectedly fast it is. > > So, what's the easiest/smartest way to get at nested objects either in a > big C_OBJECT or an ARRAY OBJECT?
I’ve done a little work in this area. From my perspective you have 2 choices: 1. Write code that will take an ARRAY OBJECT parameter and walk the array scanning each object element for the value you want. I think of this like doing a sequential search on records. You’d have to do some profiling to see if there were any performance issues with big arrays and/or big objects. 2. Build your own index for the object array. An ARRAY TEXT with values and an ARRAY LONGINT storing the element number. I think of this like an indexed search. I chose to use method 2 in the project I did. It’s super fast to do a “Find in array” on the text array, and then use the corresponding longint array value to retrieve the object array element number. And it scales well with big arrays and big objects. Tim ******************************************** Tim Nevels Innovative Solutions 785-749-3444 [email protected] ******************************************** ********************************************************************** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:[email protected] **********************************************************************

