Merge 2 jsonItem Arrays

Hi…

I have 2 identically structured jsonItems… each includes an array. I want to append the array from 1 onto the array of the other.

Each element/jsonItem of the array is in itself rather complex… it is not just a simple value.

Any easy ideas on how to do this?

Thanks in advance.

Cycle through one and append each element to the other. But perhaps I don’t understand the challenge here…

Hi Kem…

Thanks for the reply…

I tried something like this:

      for j = 0 to json2.Child("Persons").Count - 1
        json1.Child("Persons").Append(json2.Child("Persons").Child(j))
      next

… the “for” does run the expect number of times and there was no error… but the json1 “Person” array still has the same number of elements that it did before I ran the code.

Unless I have been looking at this too long “jsonItem.append” does not seem to able to append a jsonItem… Maybe a bug?

I’m not a big fan of long statements like this. My suggestion is to split it up with assignments so you can follow it easier in the debugger, something like this:

dim appendTo as JSONItem = json1.Child( "Persons" )
dim getFrom as JSONItem = json2.Child( "Persons" )
for j as integer = 0 to getFrom.Count - 1
  dim appendItem as JSONItem = getFrom.Child( j )
  appendTo.Append appendItem
next

I get the same results with your method…

In the morning I am going to try a simple test app and see if I can figure out what is going on…

Thanks

Did you trace through the method as it’s running? That should tell you what’s going on, no?

Found the problem… It is working… it was one of those “been looking at this too long” issues.

Sorry to have bothered you.