2017-02-23 91 views
0

我從我的SmartFoxServer擴展傳遞數組到我的Unity3d遊戲,但我有一個困難的時間解析。這是我如何把它在我的分機:Unity3d/SmartFoxServer解析ISFSArray

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()); 

在我Unity3d C#代碼,我做了以下內容:

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

但是,我不知道如何解析每個字符串數組。我試過這樣的事情:

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

但是,這給出了一個錯誤;如何做到這一點的任何提示:

感謝

回答

0

不要把你的字符串sfsArray,把它們放在一個sfsObject:

服務器:

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

客戶:

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"); 
    } 
}