Get Array out of Hashtable

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

zauri2000
Posts: 2
Joined: 26 Nov 2009, 14:37

Get Array out of Hashtable

Postby zauri2000 » 11 Dec 2009, 00:08

hi community,

I am trying to send a HighScore list from the MySQL DB to my clients.

On my Server AS Script

Code: Select all

if (cmd=="list"){
   var mySql = "SELECT player.Nickname, player.Score FROM player ORDER BY player.Score DESC LIMIT 10"
   var queryRes = dbase.executeQuery(mySql)
   
   var response ={}
   response._cmd="getList"
   response.db = []
   
   if (queryRes != null){
           // Cycle through all records in the ResultSet
           for (var i = 0; i < queryRes.size(); i++){
                   // Get a record
                   var tempRow = queryRes.get(i)
                  
               // This object will hold the record data that we'll send to the client
               var item = {}

                // From the record object we can get each field value
                item.name       = tempRow.getItem("Nickname")
                item.score    = tempRow.getItem("Score")
                     trace(item.name + "   "+item.score)
                response.db.push( item )
   
           }   
    _server.sendResponse(response, fromRoom, null, [user])
     }


On my Clients in Unity :

Code: Select all

void onExtensionResp(object dataObj, string type) {
if (type == SmartFoxClient.XTMSG_TYPE_XML)
          {
              SFSObject responseData = (SFSObject)dataObj;
if (responseData.GetString("_cmd")=="getList"){
         
   // HERE is my problem, how do i get the array out of the Hashtable
         }



}



How did i get the Array data out of my Hashtable ?

best regards
Zauri2000
zauri2000
Posts: 2
Joined: 26 Nov 2009, 14:37

Postby zauri2000 » 11 Dec 2009, 10:18

After 5h testing i get the solution :D

Code: Select all

if (responseData.GetString("_cmd")=="getList"){
            
         SFSObject myObject = responseData.GetObj("db");
         Debug.Log ("Size: "+ myObject.Size());
         for (int i=0; i< myObject.Size();i++){
         Debug.Log(myObject.GetObj(""+i).GetString("name")+' '+myObject.GetObj(""+i).GetString("score"));   
         }

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 1 guest