Page 1 of 1

Switch/Case block for JSON?

Posted: 18 May 2009, 23:19
by duke
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?

Posted: 19 May 2009, 08:18
by duke
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.

Posted: 19 May 2009, 10:44
by mugambs
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?

Posted: 31 May 2009, 07:26
by duke
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.

Posted: 31 May 2009, 11:30
by ThomasLund
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