Page 1 of 1

LitJson JSONArray equivalent ?

Posted: 20 Apr 2010, 12:29
by Alewinn
Hi everyone,

I'm trying to send an array to the server with LitJson without any success :(
I tryed to use the StringBuilder and the JsonWritter but the final Json string seems to be malformed ;

Code: Select all

        JsonData mess = new JsonData();
        mess["_cmd"] = NOTIFTYPE.SENDNEWCHAR.ToString();

        StringBuilder sb = new StringBuilder();
        JsonWriter W = new JsonWriter(sb);


        // Gets some data into a string array
        string[] charParts = parseCharacterString(Skin);

        for (int i = 0; i < charParts.Length; i++)


        mess[ENETCOM.PARAMS] = sb.ToString();


this sends me the following string :

Code: Select all


Any idea to get rid of the bad "\" and " ??

Posted: 20 Apr 2010, 17:05
by Alewinn
... I tryed to manually create the string from the initial array ;

Code: Select all

    private JsonData manuallyparse()
        JsonData mess = new JsonData();
        // manually create the params array
        string JSonArray = "{\"" + ENETCOM.COM + "\":\""
                            + NOTIFTYPE.SENDNEWCHAR.ToString() + "\",\""
                            + ENETCOM.PARAMS + "\":[";
        JSonArray += "\"" + this.m_Name + "\"";
        string[] charParts = parseCharacterString(this.m_Skin);
        for (int i = 0; i < charParts.Length; i++)
            JSonArray += ",\"" + charParts[i].ToString() + "\"";
        JSonArray += "]}";

        mess = JSonArray;

        return mess;

This time the message looks ok but this raise a LitJSON error saying :

Code: Select all

InvalidOperationException: Instance of JsonData is not a dictionary

Nobody already sends a JSon array to the server ???
Do i have to modify the LitJson lib ?

Posted: 21 Apr 2010, 06:01
by at

Maybe I didn't get something, but why are you trying to use LitJson directly with SFS .NET client ?

The object sent via SendXtMessage is wrapped automatically to JSON when you chose this type of data format.

All you should do is to send an xt message like this:

Code: Select all

smartFox.SendXtMessage(xtName, cmd, data, SmartFoxClient.XTMSG_TYPE_JSON);

Where data is a hashtable with the objects you need. You can put Arrays inside and all this should be wrapped automatically. This is performed by JsonMapper.ToJson method.

Posted: 21 Apr 2010, 07:21
by Alewinn
Ah ah !!
Thanks !!
I simply was too intricate in my code to see that !
As we said in french :

Code: Select all

J'avais le nez dans le guidon

I changed some things in my code and it work fine !