Page 1 of 1

foreach on SFSObject

Posted: 19 Jan 2015, 17:19
by Tatanan
Which is the proper way to make a "foreach" loop on a SFSObject?

Re: foreach on SFSObject

Posted: 20 Jan 2015, 16:41
by Lapo
SFSObject means SmartFoxServer 2X, so this is the wrong section ;) I'll move the topic.

A for each is kind of a complicated thing to do because you don't know which type of object and key you're expecting.
It can be done but you should probably describe more clearly what you're trying to do.

thanks

Re: foreach on SFSObject

Posted: 20 Jan 2015, 16:55
by Tatanan
Ok, thanks.
I put it on the server forum because we wanted it to do on the server (on Java), but it's clear.
I'll try to make without the foreach loop.

Re: foreach on SFSObject

Posted: 20 Jan 2015, 17:10
by Lapo
If you're expecting a number of items try using an array instead.
For example if you're sending a bunch of strings send a String array via SFSObj.putUtfStringArray(key, value);

If the type of these objects is not known, then you can use an SFSArray which accepts any types (among those supported).

You can then cycle on it like this:

Code: Select all

for (int i =0; i < sfsArray.size(); i++)
{
   SFSDataWrapper item = sfsArray.get(i);

   if (item.getTypeId() == SFSDataType.DOUBLE)
   ...
   ...
}
which will allow you to detect the type of each item in the array.

cheers