If you do not know the number of elements up ahead you should use a list instead of an array. If the api explicitely calls for an array you can convert the list back to an array later.
Using lists...