Switch/Case block for JSON?

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

Moderators: Lapo, Bax

duke
Posts: 31
Joined: 16 Apr 2009, 11:23

Switch/Case block for JSON?

Postby duke » 18 May 2009, 23:19

I asked this in irc last night but went to sleep soon after! How do I go about doing a switch/case block for JSONData? Like for XML I go "SFSObject dataObj = (SFSObject)data (where data is an object input of OnExtensionResponse" and "dataObj.GetString("cmd")". How do I do this same thing for JSONData?
duke
Posts: 31
Joined: 16 Apr 2009, 11:23

Postby duke » 19 May 2009, 08:18

To clarify, I can do this for xml:

Code: Select all

    void OnExtensionResponse(object data, string type)
    {
        if (type == SmartFoxClient.XTMSG_TYPE_XML)
        {
                SFSObject xmlObj = (SFSObject)data;

                switch (xmlObj.GetString("cmd"))
                {
                    case "actorMoveGet":
                        networkPlayer.ActorMove();
                        break;

                    case "actorMoveSet":
                        networkPlayer.ActorMove();
                        break;
                }
        }
    }


But not for JSON, it seems.
mugambs
Posts: 32
Joined: 11 Dec 2008, 12:05
Location: United Kingdom

Postby mugambs » 19 May 2009, 10:44

I dont know C# all that well, but could you elaborate on how you are trying to do this with JSON, and where your error etc is?

If its just a case of doing a switch on a String, have you checked that the String you retrieve from the JSON object is not null / empty?
duke
Posts: 31
Joined: 16 Apr 2009, 11:23

Postby duke » 31 May 2009, 07:26

The problem is a JSON obj isn't a SFSObject - so what is it? If it's JsonData, then I can't do a switch/case on it. My question is exactly as I put it in the first post - how do I do a switch/case for a json object.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 31 May 2009, 11:30

Hey Duke

Hope you got it solved with the help in irc.

For everyone else looking at jsondata object, check out the litjson manual - example 1.2

http://litjson.sourceforge.net/doc/manual.html

/Thomas

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 17 guests