简体   繁体   中英

Unity3d/SmartFoxServer Parse ISFSArray

I am passing an array from my SmartFoxServer extension to my Unity3d game but I am having a hard time parsing. Here is how I send it in my extension:

SFSObject resObj = new SFSObject();  
ISFSArray myArray= new SFSArray();

myArray.addUtfString("some String");
myArray.addUtfString("another string");
myArray.addUtfString("more string");

resObj.putSFSArray("myArray", myArray);
send("mySentData", resObj, gameExt.getGameRoom().getUserList()); 

In my Unity3d C# code, I do the following:

ISFSArray myNewArray= dataObject.GetSFSArray("myArray");

But, I am not sure how to parse the array for each string. I've tried something like this:

 for (int i = 0; i <= myNewArray.Size(); i++)
 {
   String w = cardsDealt[0];
 }

But this gives an error; Any tips on how to do this:

thanks

Don't put your strings in sfsArray , put them in one sfsObject :

Server :

ISFSObject resObj = new SFSObject();
resObj.putUtfString("name1",value1);
resObj.putUtfString("name2",value2);
resObj.putUtfString("name3",value3);
send("mySentData", resObj, gameExt.getGameRoom().getUserList());

Client :

private void onExtensionResponse(BaseEvent evt)
{
    string cmd = evt.Params["cmd"].ToString();
    if(cmd == "mySentData")
    {
        ISFSObject dataObject= evt.Params["params"] as ISFSObject;

        string str1 = dataObject.GetUtfString("name1");
        string str2 = dataObject.GetUtfString("name2");
        string str3 = dataObject.GetUtfString("name3");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM